Skip to main content

Sambert Ruby SDK

Use the Ruby SDK with Sambert to synthesize speech from text and save it as an MP3 file.

Prerequisites

Install the Ruby SDK and configure your API key. Replace WorkspaceId with your workspace ID in China (Beijing) 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::SambertSpeechSynthesizer.new(
  model: 'sambert-zhijia-v1',
  url: 'wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference',
  format: 'mp3',
  sample_rate: 48_000
)
File.binwrite('output.mp3', client.synthesize('您好,欢迎使用百炼。'))

SDK reference

OptionDescription
model, urlModel ID and WebSocket endpoint. The model ID also selects the voice.
format, sample_rateChoose an output format and sample rate supported by the model.
See the API reference for model-specific values and limits. Sambert sends the entire text when the task starts. synthesize waits for the audio. To receive audio chunks, register on_audio, then call start(text) and wait_finished. Select the voice through model. Use an audio format and sample rate supported by the model.