Skip to content

Instantly share code, notes, and snippets.

@jeanpaul
Created October 15, 2023 10:25
Show Gist options
  • Save jeanpaul/f08ec605ab43befd5cf24336f45506eb to your computer and use it in GitHub Desktop.
Save jeanpaul/f08ec605ab43befd5cf24336f45506eb to your computer and use it in GitHub Desktop.
import sys
from pathlib import Path
import openai
from pydub import AudioSegment
podcast_file = sys.argv[1]
openai.api_key_path = Path("~/.openai-api-key.txt").expanduser()
podcast = AudioSegment.from_mp3(podcast_file)
ten_minutes = 10 * 60 * 1000
first_10_minutes = podcast[:ten_minutes]
for segment in podcast[::ten_minutes]:
transcript = openai.Audio.transcribe(
"whisper-1",
segment.export("/tmp/segment.mp3", format="mp3")
)
print(transcript.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment