This tutorial demonstrates translating a Spanish audio clip into English text using OpenAI’s Whisper API.
In this tutorial, we’ll demonstrate how to translate a short Spanish audio clip into English text using OpenAI’s Whisper API. We’ll process a 20-second MP3 segment (up to 25 MB) extracted from an Easy Spanish YouTube video and send it to the API in one request.
import osimport openaiimport IPython.display as ipd# 1. Configure API keyopenai.api_key = os.getenv("OPENAI_API_KEY")# 2. Load and play the Spanish audio clipfile_name = "data/Spanish.mp3"audio_file = open(file_name, "rb")ipd.display(ipd.Audio(file_name))# 3. Call Whisper for translationresult = openai.Audio.translate("whisper-1", audio_file)# 4. Output the English translationprint(result.text)
Once you have the translated text, you can pass it to GPT-4 (or any other LLM) for further processing—such as summarization, sentiment analysis, or content moderation.