Gen AI — Audio Generation
OpenAI TTS
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="Hello! Welcome to our AI tutorial."
)
response.stream_to_file("output.mp3")
Voices
Available voices: alloy, echo, fable, onyx, nova, shimmer
for voice in ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]:
response = client.audio.speech.create(
model="tts-1",
voice=voice,
input=f"This is the {voice} voice."
)
response.stream_to_file(f"{voice}.mp3")
Whisper (Speech to Text)
audio_file = open("audio.mp3", "rb")
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
print(transcript.text)
Translation
audio_file = open("spanish.mp3", "rb")
translation = client.audio.translations.create(
model="whisper-1",
file=audio_file
)
print(translation.text) # English translation
ElevenLabs
import elevenlabs
elevenlabs.set_api_key("your-key")
audio = elevenlabs.generate(
text="Hello! This is a natural sounding voice.",
voice="Rachel"
)
elevenlabs.save(audio, "output.mp3")
Mini Practice
- Generate speech with different voices
- Transcribe audio with Whisper
- Compare TTS providers
- Build a voice assistant
Up Next
Continue with Video Generation - AI video creation.
Related Topics
Frequently Asked Questions about Audio Generation
What is Audio Generation in Gen AI?
Audio Generation is a fundamental concept in Gen AI. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Audio Generation?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Audio Generation.
Why is Audio Generation important in Gen AI?
Audio Generation is essential for Gen AI development. Understanding this concept will help you write better code and solve real-world problems more effectively.