Now live New models for transcription and text-to-speech. AssemblyAI-STT-3.7 AssemblyAI-TTS-1
Insights & Use Cases

How to transcribe audio in Ruby with AssemblyAI-STT-3.7

Transcribe audio in Ruby with only the standard library: upload a file, submit it to AssemblyAI-STT-3.7, poll, and print speaker-labeled turns. Runnable script.

Abstract green cylinder illustration

Written by

Niels Swimberghe

Published on

23 November 2026

You can add speech recognition to a Ruby app with nothing but the standard library. Net::HTTP uploads the audio, submits a transcription job to AssemblyAI and polls for the result, and json reads it back. No gem, no native extension.

This tutorial builds one Ruby script that transcribes a local file or a public URL with AssemblyAI-STT-3.7, splits the result by speaker and prints it. The full script is in the companion repo, kelsey-aai/transcribe-audio-ruby.

A note on the gem: the assemblyai Ruby gem was discontinued in April 2025. Its last release came out before the speech_models parameter existed, so it can't select AssemblyAI-STT-3.7. The calls below are plain HTTP and match the API reference exactly.

How the script works

Step Endpoint What it returns
1. Upload a local file POST /v2/upload A private upload_url only your project can use
2. Submit the job POST /v2/transcript A transcript id with status queued
3. Poll for the result GET /v2/transcript/{id} The text, words, timestamps and speaker turns once status is completed

Audio that's already at a public URL skips step 1.

Prerequisites

  • Ruby 2.6 or later. Nothing to install from RubyGems.
  • An AssemblyAI API key. Sign up and copy it from the dashboard. New accounts get $50 in free credits for the speech APIs.

Export the key so the script can read it:

export ASSEMBLYAI_API_KEY=your_key_here

Set up the request helper

Create transcribe.rb. All three endpoints share the same pattern: send a request with your key in the authorization header, raise on an error status and parse the JSON body. One helper covers them:

require "json"
require "net/http"
require "uri"

BASE_URL = ENV.fetch("ASSEMBLYAI_BASE_URL", "https://api.assemblyai.com")
API_KEY = ENV["ASSEMBLYAI_API_KEY"]

abort "Set the ASSEMBLYAI_API_KEY environment variable first." if API_KEY.nil? || API_KEY.empty?

# Sends a request and returns the parsed JSON body, or raises on an HTTP error.
def request(method, path, body: nil, content_type: nil)
  uri = URI("#{BASE_URL}#{path}")
  req = method.new(uri)
  req["authorization"] = API_KEY
  req["content-type"] = content_type if content_type
  req.body = body if body

  res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
    http.request(req)
  end
  raise "HTTP #{res.code}: #{res.body}" unless res.is_a?(Net::HTTPSuccess)

  JSON.parse(res.body)
end

ASSEMBLYAI_BASE_URL defaults to the US endpoint. Set it to https://api.eu.assemblyai.com to process audio in the EU.

Step 1: Upload a local file

POST /v2/upload takes the file's raw bytes as the body and returns an upload_url:

# Step 1: upload a local file and get back a private URL the API can read.
def upload(path)
  request(Net::HTTP::Post, "/v2/upload",
          body: File.binread(path),
          content_type: "application/octet-stream")["upload_url"]
end

That URL only works with API keys from the same project. A key from another project gets a 403.

Step 2: Submit the job on AssemblyAI-STT-3.7

Choose the model with speech_models. It's a list, and ["assemblyai-stt-3-7"] selects AssemblyAI-STT-3.7, which covers 32 languages with automatic language detection and code switching. speaker_labels: true splits the result into speaker turns:

# Step 2: submit the transcription job on AssemblyAI-STT-3.7.
def submit(audio_url)
  params = {
    audio_url: audio_url,
    speech_models: ["assemblyai-stt-3-7"],
    speaker_labels: true
  }
  request(Net::HTTP::Post, "/v2/transcript",
          body: JSON.generate(params),
          content_type: "application/json")["id"]
end

On English conversations, AssemblyAI-STT-3.7 has the lowest diarization error rate of the pre-recorded APIs AssemblyAI measured, 10.7%, ahead of ElevenLabs Scribe v3 at 12.0%. If speaker labels are new to you, start with what speaker diarization is and how it works.

Get a Free API Key

Sign up and transcribe your first file on AssemblyAI-STT-3.7 with $50 in free credits for the speech APIs.

Get Free API Key

Step 3: Poll until the transcript is ready

Jobs run asynchronously, so fetch the transcript until its status is completed or error. Polling every 3 seconds, as the docs do, stays well under the limit of 60 requests per minute for each key and transcript:

# Step 3: poll until the status is completed or error.
def wait_for_completion(transcript_id)
  loop do
    transcript = request(Net::HTTP::Get, "/v2/transcript/#{transcript_id}")
    case transcript["status"]
    when "completed" then return transcript
    when "error" then raise "Transcription failed: #{transcript['error']}"
    end
    sleep 3
  end
end

In a Rails app, don't block a web request on this loop. Submit with a webhook_url and let AssemblyAI POST to your app when the transcript is ready, or run the polling inside a background job. The guide to transcription webhooks covers the receiving side.

Step 4: Print the result

The last part of the script decides whether to upload, then prints the model that ran, the full text and one line per entry in utterances:

# A local file path or a public URL. Defaults to the sample file from the docs.
source = ARGV[0] || "https://assembly.ai/wildfires.mp3"
audio_url = source.start_with?("http://", "https://") ? source : upload(source)

transcript_id = submit(audio_url)
puts "Submitted transcript #{transcript_id}"

transcript = wait_for_completion(transcript_id)

# Step 4: print the full text, then one line per speaker turn.
puts "Model used: #{transcript['speech_model_used']}"
puts
puts transcript["text"]
puts
(transcript["utterances"] || []).each do |utterance|
  puts "Speaker #{utterance['speaker']}: #{utterance['text']}"
end

Run it

# The sample file from the docs
ruby transcribe.rb

# Your own file or URL
ruby transcribe.rb ./meeting.mp3

The output (abridged) looks like this:

Submitted transcript 6b0f2c1e-...
Model used: assemblyai-stt-3-7

Smoke from hundreds of wildfires in Canada is triggering air quality alerts...

Speaker A: Smoke from hundreds of wildfires in Canada is triggering air quality alerts...
Speaker B: ...
Try AssemblyAI-STT-3.7 on Your Own Audio

Upload a recording in the playground and check the transcript before you write any code.

Open the Playground

Tune the output

Each option is one more key in the params hash:

Goal Add to params Notes
Clean, readable text disfluencies: false AssemblyAI-STT-3.7 keeps fillers, repetitions and false starts by default
Languages beyond the 32 speech_models: ["assemblyai-stt-3-7", "universal-2"] Falls through to Universal-2 for 99 languages in total
Known language mix language_codes: ["en", "es"] Don't combine with language_code or language_detection
Names and jargon keyterms_prompt: ["Sidekiq", "ActiveRecord"] Up to 1,000 terms on AssemblyAI-STT-3.7
No polling webhook_url: "https://your.app/hook" AssemblyAI calls you when the job finishes

Verbatim transcription with an API explains when to keep fillers and when to drop them. Keep keyterm lists to words the model is likely to miss; when keyterm prompting backfires shows what goes wrong otherwise. For recordings that switch languages mid-sentence, see the multilingual speech-to-text guide.

What it costs

AssemblyAI-STT-3.7 is $0.21 per hour of audio and speaker labels add $0.02 per hour, per the pricing page. Keyterms prompting on AssemblyAI-STT-3.7 is $0.05 per hour. A 10-minute file with speaker labels comes to about 4 cents.

Where to go next

Add Speech Recognition to Your Ruby App

Clone the script, add your key and transcribe your first file in a few minutes.

Start Building Free

Frequently Asked Questions (FAQs)

How do I do speech recognition in Ruby?

Call a speech-to-text API from Ruby's built-in Net::HTTP. With AssemblyAI, upload the file to /v2/upload, submit /v2/transcript with speech_models: ["assemblyai-stt-3-7"], then poll /v2/transcript/{id} until the status is completed and read the text field. The whole script is about 70 lines and needs no gems.

Is the AssemblyAI Ruby gem still supported?

No. The assemblyai gem was discontinued in April 2025. Published versions still install, but they predate the speech_models parameter and can't select AssemblyAI-STT-3.7. Calling the REST API directly, as this tutorial does, is the supported path.

Can I use this in a Rails app?

Yes. Put the upload and submit calls in a service object or a background job (Sidekiq, Active Job) rather than a controller action, and pass a webhook_url so AssemblyAI notifies your app when the transcript is ready instead of a worker polling.

How do I transcribe a local file in Ruby?

Upload it first. File.binread reads the bytes, POST /v2/upload returns an upload_url, and you pass that URL as audio_url when you submit the transcript.

Which languages does AssemblyAI-STT-3.7 support?

AssemblyAI-STT-3.7 covers 32 languages with automatic language detection and code switching. For audio that might fall outside those 32, set speech_models to ["assemblyai-stt-3-7", "universal-2"] and the job falls through to Universal-2, for 99 languages in total.

How much does speech recognition in Ruby cost with AssemblyAI?

The same as from any other language: AssemblyAI-STT-3.7 is $0.21 per hour of audio, with add-ons such as speaker labels ($0.02 per hour) priced separately. New accounts get $50 in free credits for the speech APIs.