Skip to content

Instantly share code, notes, and snippets.

@shawnho1018
Last active October 18, 2025 04:37
Show Gist options
  • Select an option

  • Save shawnho1018/cccefc21f6d10926db02c0c678917abd to your computer and use it in GitHub Desktop.

Select an option

Save shawnho1018/cccefc21f6d10926db02c0c678917abd to your computer and use it in GitHub Desktop.
PodCast with Gemini Sample code
from google import genai
from google.genai import types
import wave
import datetime
from script import script
# Set up the wave file to save the output:
def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
with wave.open(filename, "wb") as wf:
wf.setnchannels(channels)
wf.setsampwidth(sample_width)
wf.setframerate(rate)
wf.writeframes(pcm)
client = genai.Client()
prompt = script
response = client.models.generate_content(
model="gemini-2.5-flash-preview-tts",
contents=prompt,
config=types.GenerateContentConfig(
response_modalities=["AUDIO"],
speech_config=types.SpeechConfig(
multi_speaker_voice_config=types.MultiSpeakerVoiceConfig(
speaker_voice_configs=[
types.SpeakerVoiceConfig(
speaker='Emma',
voice_config=types.VoiceConfig(
prebuilt_voice_config=types.PrebuiltVoiceConfig(
voice_name='Leda',
)
)
),
types.SpeakerVoiceConfig(
speaker='Eason',
voice_config=types.VoiceConfig(
prebuilt_voice_config=types.PrebuiltVoiceConfig(
voice_name='Puck',
)
)
),
]
)
)
)
)
data = response.candidates[0].content.parts[0].inline_data.data
file_name=f'out_{datetime.datetime.now().strftime("%Y%m%d_%H%M%S")}.wav'
wave_file(file_name, data) # Saves the file to current directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment