QwenCloudBRASIL
Tradução de apoio para consulta. Código e identificadores técnicos preservados. Consultar referência original ↗

Qwen3-TTS-Flash-Realtime

qwen3-tts-flash-realtime

Visão geral

Transforma texto em fala para narração, assistentes e experiências de áudio. A saída em tempo real permite começar a reproduzir a voz durante a geração.

Características

Prefixo Completação

Activar o Modo Parcial ao chamar o Qwen API para fazer o modelo continuar estritamente do seu prefixo fornecido texto.https://docs.qwencloud.com/developer-guides/text-generation/partial-mode)

Chamada de Função

Use a função chamando para conectar modelos de linguagem com ferramentas e sistemas externos.https://docs.qwencloud.com/developer-guides/text-generation/function-calling)

Cache.

Contexto Cache armazena prefixos compartilhados para pedidos de longo contexto para reduzir a computação repetida, melhorar a latência e menor custo.https://docs.qwencloud.com/developer-guides/text-generation/context-cache#implicit-cache)

Saídas Estruturadas

Saídas estruturadas ajudam a garantir que o modelo retorne uma string JSON no formato esperado.https://docs.qwencloud.com/developer-guides/text-generation/structured-output)

Batches.

Processa assíncronamente pedidos em lotes para reduzir custos.https://docs.qwencloud.com/developer-guides/run-and-scale/cost-optimization#batch-calling)

Active a busca na web para que o modelo possa responder com dados recuperados em tempo real.https://docs.qwencloud.com/developer-guides/text-generation/web-search#enable-web-search)

Afinação

Modelos de trens em dados amostrais para melhor adaptá-los a tarefas específicas.https://docs.qwencloud.com/developer-guides/fine-tuning/overview)

-Preços.

Limites de Taxa

Referência da API

[Ligar API] (https://home.qwencloud.com/api-keys) DashScope Java Python Python

import os
import base64
import threading
import time
import dashscope
from dashscope.audio.qwen_tts_realtime import *

qwen_tts_realtime: QwenTtsRealtime = None
text_to_synthesize = [
    'Right?~ I especially love this kind of supermarket,',
    'Especially during the New Year',
    'Going to the supermarket',
    'It just makes me feel',
    'Super, super happy!',
    'I want to buy so many things!'
]

DO_VIDEO_TEST = False

def init_dashscope_api_key ():
    """
        Set your DashScope API-key. More information:
        https://github.com/aliyun/alibabacloud-bailian-speech-demo/blob/master/PREREQUISITES.md
    """

    if 'DASHSCOPE_API_KEY' in os.environ:
        dashscope.api_key = os.environ[
            'DASHSCOPE_API_KEY']  # load API-key from environment variable DASHSCOPE_API_KEY
    else:
        dashscope.api_key = 'your-dashscope-api-key'  # set API-key manually

class MyCallback (QwenTtsRealtimeCallback):
    def __init__(self):
        self.complete_event = threading.Event()
        self.file = open ('result_24k.pcm', 'wb')

    def on_open (self) -> None:
        print ('connection opened, init player')

    def on_close (self, close_status_code, close_msg) -> None:
        self.file.close()
        print ('connection closed with code: {}, msg: {}, destroy player'.format (close_status_code, close_msg))

    def on_event (self, response: str) -> None:
        try:
            global qwen_tts_realtime
            type = response['type']
            if 'session.created' == type:
                print ('start session: {}'.format (response['session']['id']))
            if 'response.audio.delta' == type:
                recv_audio_b64 = response['delta']
                self.file.write(base64.b64decode(recv_audio_b64))
            if 'response.done' == type:
                print (f'response {qwen_tts_realtime.get_last_response_id()} done')
            if 'session.finished' == type:
                print ('session finished')
                self.complete_event.set ()
        except Exception as e:
            print ('[Error] {}'.format (e))
            return

    def wait_for_finished (self):
        self.complete_event.wait()

if __name__  == '__main__':
    init_dashscope_api_key()

    print ('Initializing ...')

    callback = MyCallback()

    qwen_tts_realtime = QwenTtsRealtime(
        model='qwen3-tts-flash-realtime',
        callback=callback,
        )

    qwen_tts_realtime.connect()
    qwen_tts_realtime.update_session(
        voice = 'Cherry',
        response_format = AudioFormat.PCM_24000HZ_MONO_16BIT,
        mode = 'server_commit'
    )
    for text_chunk in text_to_synthesize:
        print (f'send texd: {text_chunk}')
        qwen_tts_realtime.append_text(text_chunk)
        time.sleep(0.1)
    qwen_tts_realtime.finish()
    callback.wait_for_finished()
    print ('[Metric] session: {}, first audio delay: {}'.format (
                    qwen_tts_realtime.get_session_id(),
                    qwen_tts_realtime.get_first_audio_delay(),
                    ))

Cota Livre 10 mil de desconto. [Assinar para rastrear o uso] (https://account.qwencloud.com/sso/OIDCAuth?oauth_callback=https%3A%2F%2Fwww.qwencloud.com%2Fmodels%2Fqwen3-tts-flash-realtime)

* Valores em reais sujeitos a ajustes e a flutuações cambiais. Conversões estimadas, sem impostos, spread ou tarifas; confirme o valor final na plataforma oficial.