Created
April 4, 2023 07:37
-
-
Save spech66/5385a78ad0af4cb4f287e0543505d0a2 to your computer and use it in GitHub Desktop.
OpenAI whisper speech to text with ffmpeg based ogg->mp3 converter for WhatsApp messages
This file contains 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
import os | |
import sys | |
import openai | |
# Fail if no commandline argument is provided | |
if len(sys.argv) < 2: | |
print("Please provide an audio file") | |
exit(1) | |
audio_file_name = sys.argv[1] | |
# Check if file exists | |
if not os.path.isfile(audio_file_name): | |
print("File does not exist") | |
exit(1) | |
# If file is in ogg format convert it to mp3 | |
if audio_file_name.endswith(".ogg"): | |
os.system(f"ffmpeg -i '{audio_file_name}' -ab 320k '{audio_file_name}.mp3'") | |
audio_file_name = f"{audio_file_name}.mp3" | |
audio_file= open(audio_file_name, "rb") | |
transcript = openai.Audio.transcribe("whisper-1", audio_file, language="de") | |
print(transcript) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment