Skip to content

Commit 172a00b

Browse files
committed
Add transcribe()
1 parent 0b2234b commit 172a00b

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

rabbithole/transcribe.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""rabbithole.transcribe module"""
2+
3+
import openai
4+
5+
from rabbithole.mp3 import chunk_mp3
6+
7+
8+
def transcribe(filepath: str) -> str:
9+
"""
10+
Transcribe a mp3 file using OpenAI's Whisper API
11+
:param filepath: Path to mp3 file
12+
:return: Transcription
13+
"""
14+
15+
# Split the file into chunks
16+
files = chunk_mp3(filepath)
17+
18+
transcripts = []
19+
20+
for file in files:
21+
with open(file, "rb") as audio_file:
22+
transcripts.append(openai.Audio.transcribe("whisper-1", audio_file))
23+
24+
return " ".join(transcripts)

0 commit comments

Comments
 (0)