Created
October 21, 2023 15:23
-
-
Save lordjabez/db5b3fce956264b9ed5d4d3a66575a9e to your computer and use it in GitHub Desktop.
Transcribe audio files using OpenAI's whisper-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import pathlib | |
import pprint | |
import sys | |
import cachier | |
import openai | |
audio_filenames = sys.argv[1:] | |
home_folder = pathlib.Path.home() | |
api_key_filename = f'{home_folder}/.config/openai/api-key.txt' | |
openai.api_key = open(api_key_filename).read().strip() | |
@cachier.cachier() | |
def get_transcript(audio_filename): | |
with open(audio_filename, 'rb') as audio_file: | |
response = openai.Audio.translate('whisper-1', audio_file) | |
return response['text'] | |
transcripts = [] | |
for audio_filename in audio_filenames: | |
transcript = get_transcript(audio_filename) | |
print(transcript) | |
transcripts.append(transcript) | |
print(' '.join(transcripts)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment