Skip to main content

Qwen-Audio-ASR-Streaming Ruby SDK

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 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::FunAsrSpeechTranscriber.new(
  model: 'qwen-audio-3.1-asr-flash-streaming',
  url: 'wss://WorkspaceId.ap-southeast-1.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

OptionDescription
model, urlModel ID and WebSocket endpoint.
format, sample_rateAudio 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.