Skip to main content

Qwen-Audio-TTS Ruby SDK

Use the Ruby SDK with Qwen-Audio-TTS to synthesize speech from text and save it as a WAV file.

Prerequisites

Install the Ruby SDK and configure your API key. Replace WorkspaceId with your workspace ID in Singapore and use an API key from the same region.

Quick start

Save the example as example.rb and run ruby example.rb.
require 'dashscope'

client = DashScope::Speech::CosyVoiceSpeechSynthesizer.new(
  model: 'qwen-audio-3.1-tts-flash',
  url: 'wss://WorkspaceId.ap-southeast-1.maas.aliyuncs.com/api-ws/v1/inference',
  voice: 'longanfengyue_v3.1',
  format: 'wav',
  sample_rate: 16_000
)
File.binwrite('output.wav', client.synthesize(['Hello, welcome to Model Studio.']))

SDK reference

OptionDescription
model, url, voiceModel ID, WebSocket endpoint, and a voice supported by the model.
format, sample_rateOutput audio format and sample rate.
See the API reference for model-specific values and limits. synthesize accepts text segments and returns the complete audio. To receive audio as you send text, register on_audio and call start, send_text, and stop. Choose a voice supported by the model. Follow the model limits for format and sample_rate. Read usage or usage_text when synthesis completes.