转录 API 的输入是您要进行转录的音频文件以及所需输出格式的音频文字稿。我们目前支持多种输入和输出文件格式。
# Note: you need to be using OpenAI Python v0.27.0 for the code below to workimport openaiaudio_file=open("/path/to/file/audio.mp3","rb")transcript = openai.Audio.transcribe("whisper-1", audio_file)
默认情况下,响应类型将是包含原始文本的 JSON。
{
"text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger.
....
}
# Note: you need to be using OpenAI Python v0.27.0 for the code below to work
import openai
audio_file= open("/path/to/file/german.mp3", "rb")
transcript = openai.Audio.translate("whisper-1", audio_file)
Hello, my name is Wolfgang and I come from Germany. Where are you heading today?
from pydub import AudioSegment
song = AudioSegment.from_mp3("good_morning.mp3")
# PyDub handles time in milliseconds
ten_minutes = 10 * 60 * 1000
first_10_minutes = song[:ten_minutes]
first_10_minutes.export("good_morning_10.mp3", format="mp3")