Qwen-Audio-ASR-Streaming Ruby SDK
Updated at:
Use the Ruby SDK with Qwen-Audio-ASR-Streaming to transcribe 16 kHz, 16-bit, mono raw PCM audio.
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::FunAsrSpeechTranscriber.new(
model: 'qwen-audio-3.1-asr-flash-streaming',
url: 'wss://WorkspaceId.cn-beijing.maas.aliyuncs.com/api-ws/v1/inference',
format: 'pcm',
sample_rate: 16_000
)
client.on_sentence_end = ->(sentence, _) { puts sentence.text }
client.on_failed = ->(error) { warn error.inspect }
client.transcribe_pcm_file('input.pcm')
SDK reference
| Option | Description |
|---|---|
model, url | Model ID and WebSocket endpoint. |
format, sample_rate | Audio format and sample rate. Match the audio input. |
See the API reference for model-specific values and limits.
transcribe_pcm_file streams audio at real-time speed and waits for the task to finish. Read finalized sentences in on_sentence_end. To stream frames yourself, call start, send_audio, and stop. Handle task errors in on_failed.
Use connect_timeout, start_timeout, and stop_timeout to control the connection, task startup, and completion. Set format and sample_rate to match your audio.
Is this page helpful?