Use the Ruby SDK with CosyVoice to synthesize speech from text and save it as a WAV file.
Prerequisites
Download dashscope-1.2.0.gem and run gem install --local ./dashscope-1.2.0.gem to install the SDK. Set the DASHSCOPE_API_KEY environment variable to an API key from Singapore.
Quick start
Save the example as example.rb and run ruby example.rb.
SDK reference
| Option | Description |
|---|---|
model, url, voice | Model ID, WebSocket endpoint, and a voice supported by the model. |
format, sample_rate | Output audio format and sample rate. |
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.