You are viewing a single comment's thread from:

RE: LeoThread 2024-10-28 03:27

Before we dive into the code, you need two things:

OpenAI API Key
Sample audio file
First, install the OpenAI library (Use ! only if you are installing it on the notebook):

!pip install openai
Now let’s write the code to transcribe a sample speech file to text:

#Import the openai Library
from openai import OpenAI

Create an api client

client = OpenAI(api_key="YOUR_KEY_HERE")

Load audio file

audio_file= open("AUDIO_FILE_PATH", "rb")

Transcribe

transcription = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)

Print the transcribed text

print(transcription.text)