Chapter 35
Create a Multi-Speaker Podcast with Gemini & Text-to-Speech
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.Create a Multi-Speaker Podcast with Gemini & Text-to-Speech
| Authors |
|---|
| Souvik Mukherjee |
| Holt Skinner |
Overview
This notebook demonstrates how to use the Gemini API in Agent Platform to generate an engaging multi-speaker podcast using Gemini Text-to-Speech voices.
This can be useful for creating interviews, interactive storytelling, video games, e-learning platforms, and accessibility solutions.
The steps performed include:
- Load a PDF file from a Google Cloud Storage bucket or public URL
- Summarize the content using Gemini
- Create a multi speaker conversation using Gemini Text-to-Speech.
- Generate the audio as WAV.
For a more advanced example using LangGraph, check out Build Your Own AI Podcasting Agent with LangGraph & Gemini: AI-Powered Podcast Creation with Automated Research, Writing, and Refinement
Get started
Install Google Gen AI SDK for Python
Install the following packages required to execute this notebook.
%pip install --upgrade --quiet google-genaiAuthenticate your notebook environment
If you are running this notebook in Google Colab, run the cell below to authenticate your account.
import sys
if "google.colab" in sys.modules:
from google.colab import auth
auth.authenticate_user()Set Google Cloud project information
To get started using Agent Platform, you must have an existing Google Cloud project and enable the Agent Platform API.
Learn more about setting up a project and a development environment.
import os
from google import genai
# fmt: off
PROJECT_ID = "[your-project-id]" # @param {type: "string", placeholder: "[your-project-id]", isTemplate: true}
LOCATION = "global" # @param {type: "string", placeholder: "[your-project-id]", isTemplate: true}
# fmt: on
if not PROJECT_ID or PROJECT_ID == "[your-project-id]":
PROJECT_ID = str(os.environ.get("GOOGLE_CLOUD_PROJECT"))
if not LOCATION:
LOCATION = os.environ.get("GOOGLE_CLOUD_REGION")
client = genai.Client(enterprise=True, project=PROJECT_ID, location=LOCATION)Import libraries
import io
import wave
from IPython.display import Audio, Markdown, display
from google.genai.types import (
GenerateContentConfig,
MultiSpeakerVoiceConfig,
Part,
PrebuiltVoiceConfig,
SpeakerVoiceConfig,
SpeechConfig,
VoiceConfig,
)Load the Gemini model
Learn more about all Gemini models on Agent Platform.
Learn more about Gemini Text-to-Speech.
MODEL_ID = "gemini-3.6-flash" # @param {type: "string"}
TTS_MODEL_ID = "gemini-3.1-flash-tts-preview" # @param {type: "string"}Helper functions
def wave_bytes(pcm: bytes) -> bytes:
"""Wrap 24 kHz 16-bit mono PCM in a WAV container for in-notebook playback."""
buffer = io.BytesIO()
with wave.open(buffer, "wb") as wf:
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(24000)
wf.writeframes(pcm)
return buffer.getvalue()Generate the podcast script from the content
For this example, we will be using the "Attention Is All You Need" paper from arXiv.
You can replace this with the URL with any publicly-accessible PDF.
PDF_URL = "https://arxiv.org/pdf/1706.03762" # @param {type: "string"}
prompt = """
The dialogue should be engaging and natural, with each speaker contributing roughly equal amounts.
Return the dialogue as a freeform script in this format:
R: [dialogue]
S: [dialogue]
Use the following information to create the content for the podcast dialogue:
"""
response = client.models.generate_content(
model=MODEL_ID,
contents=[
prompt,
Part.from_uri(file_uri=PDF_URL, mime_type="application/pdf"),
],
config=GenerateContentConfig(
system_instruction="""You are a podcast writer. Your task is to generate a fun podcast-style dialogue between two speakers, Speaker R and Speaker S for Text-to-Speech.""",
),
)
dialogue = response.text
print("Generated Dialogue:")
display(Markdown(dialogue))Create the audio content
tts_prompt = f"""TTS the following conversation between speakers R & S: {dialogue}"""
response = client.models.generate_content(
model="gemini-3.1-flash-tts-preview",
contents=tts_prompt,
config=GenerateContentConfig(
speech_config=SpeechConfig(
language_code="en-us",
multi_speaker_voice_config=MultiSpeakerVoiceConfig(
speaker_voice_configs=[
SpeakerVoiceConfig(
speaker="R",
voice_config=VoiceConfig(
prebuilt_voice_config=PrebuiltVoiceConfig(
voice_name="Kore",
)
),
),
SpeakerVoiceConfig(
speaker="S",
voice_config=VoiceConfig(
prebuilt_voice_config=PrebuiltVoiceConfig(
voice_name="Achird",
)
),
),
]
),
),
),
)Play the audio
audio_data = wave_bytes(response.candidates[0].content.parts[0].inline_data.data)
Audio(audio_data)