|$ curl https://forge-ai.dev/api/markdown?path=docs/ai/audio
$cat docs/audio-&-speech-models.md
updated Recently·30 min read·published

Audio & Speech Models

AIAdvanced🎯Free Tools
Introduction

Audio AI spans speech recognition (transcription), text-to-speech (generation), speaker identification, sound event detection, music generation, and audio understanding. Modern models like OpenAI Whisper, ElevenLabs TTS, and AudioCraft have dramatically improved quality and accessibility of audio AI.

The field has converged towards unified architectures that process multiple audio tasks: Whisper does transcription, translation, and language identification; Meta's AudioCraft handles music generation, sound generation, and compression. Multimodal models increasingly process audio alongside text and images.

Speech Recognition with Whisper

OpenAI Whisper is a general-purpose speech recognition model trained on 680,000 hours of multilingual data. It supports transcription (speech to text in the same language), translation (speech to English text), and language identification. Whisper handles background noise, accents, and diverse audio quality better than previous models.

whisper-transcription.py
Python
1# Whisper — transcription via API
2from openai import OpenAI
3
4client = OpenAI()
5
6# Audio transcription (same language)
7response = client.audio.transcriptions.create(
8 model="whisper-1",
9 file=open("meeting.mp3", "rb"),
10 response_format="verbose_json",
11 timestamp_granularities=["segment"],
12)
13
14print(response.text)
15# Each segment has start/end timestamps
16for segment in response.segments:
17 print(f"[{segment.start:.1f}s -> {segment.end:.1f}s] {segment.text}")
18
19# Translation to English
20response = client.audio.translations.create(
21 model="whisper-1",
22 file=open("spanish_audio.mp3", "rb"),
23)
24
25# Whisper local inference (open-source model)
26import whisper
27
28model = whisper.load_model("large-v3")
29result = model.transcribe(
30 "audio.mp3",
31 language="en",
32 temperature=0.0,
33 word_timestamps=True,
34)
35
36print(result["text"])
37for seg in result["segments"]:
38 print(f"{seg['start']:.1f}s: {seg['text']}")

info

For real-time transcription, use Whisper's tiny or base models locally. For highest accuracy on difficult audio, use the large-v3 model or the API. Pre-process audio to 16kHz mono WAV for optimal results.
Text-to-Speech Generation

Modern TTS models produce natural, expressive speech with controllable pace, pitch, and emotion. ElevenLabs offers the most realistic voices with voice cloning from short samples. OpenAI TTS provides six built-in voices with two quality tiers. Open-source options include Coqui TTS and Bark.

tts-generation.py
Python
1# OpenAI TTS
2from openai import OpenAI
3import io
4
5client = OpenAI()
6
7response = client.audio.speech.create(
8 model="tts-1-hd", # High quality
9 voice="nova", # alloy, echo, fable, nova, onyx, shimmer
10 input="Hello, welcome to the audio AI guide. Today we'll explore speech synthesis.",
11 speed=1.0,
12)
13
14# Stream to file
15response.stream_to_file("output.mp3")
16
17# ElevenLabs TTS
18import elevenlabs
19from elevenlabs.client import ElevenLabs
20
21client = ElevenLabs(api_key="your-key")
22
23# Generate speech with a premade voice
24audio = client.generate(
25 text="This is generated speech from ElevenLabs.",
26 voice="Rachel",
27 model="eleven_multilingual_v2",
28)
29
30# Voice cloning from audio sample
31voice = client.clone(
32 name="Custom Voice",
33 files=["sample.mp3"],
34 description="Natural speaking voice",
35)
36audio = client.generate(
37 text="This is a cloned voice speaking.",
38 voice=voice.voice_id,
39)
40
41# Play audio
42elevenlabs.play(audio)
Sound Detection & Music Generation

Sound event detection identifies non-speech audio events (glass breaking, dog barking, car engine). AudioCraft (MusicGen + AudioGen) from Meta generates music and sound effects from text descriptions. These models use audio tokenization and transformer architectures similar to text generation.

audiocraft-sound.py
Python
1# AudioCraft — music and sound generation
2from audiocraft.models import MusicGen, AudioGen
3
4# Music generation
5music_model = MusicGen.get_pretrained("melody")
6music_model.set_generation_params(duration=8)
7
8descriptions = [
9 "upbeat electronic dance music with heavy bass",
10 "calm classical piano piece with strings",
11]
12
13wav = music_model.generate(descriptions)
14# wav shape: [batch, channels, samples]
15
16# Sound effect generation
17sound_model = AudioGen.get_pretrained("facebook/audiogen-medium")
18sound_model.set_generation_params(duration=5)
19
20sounds = sound_model.generate([
21 "dog barking in the distance",
22 "car engine starting and driving away",
23])
24
25# Sound event classification
26from transformers import AutoModelForAudioClassification
27import torchaudio
28
29model = AutoModelForAudioClassification.from_pretrained(
30 "MIT/ast-finetuned-audioset-10-10-0.2"
31)
32waveform, sample_rate = torchaudio.load("sound.wav")
33inputs = processor(waveform, sampling_rate=sample_rate, return_tensors="pt")
34outputs = model(**inputs)
35predicted_class_id = outputs.logits.argmax(-1).item()
36label = model.config.id2label[predicted_class_id]
Key Takeaways
  • Whisper provides state-of-the-art transcription with multilingual support and speaker detection
  • TTS models (ElevenLabs, OpenAI) produce natural speech with voice cloning capabilities
  • AudioCraft generates music and sound effects from text descriptions
  • Pre-process audio to 16kHz mono WAV for optimal recognition accuracy
  • Combine ASR + TTS for voice chatbots and real-time translation pipelines

Community

Get help on Slack, Discord or VIP

Stuck on a guide? Join the community and ask.