Spaces:
Runtime error
Runtime error
Juan Ignacio Cuiule commited on
Commit ·
9974834
1
Parent(s): 3c99133
Fix audio segmentation and transcription in app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ def transcribe_audio(audio_file, api_key):
|
|
| 8 |
|
| 9 |
audio = AudioSegment.from_mp3(audio_file)
|
| 10 |
segment_duration = 10 * 60 * 1000
|
| 11 |
-
num_segments =
|
| 12 |
|
| 13 |
segments = []
|
| 14 |
|
|
@@ -22,8 +22,9 @@ def transcribe_audio(audio_file, api_key):
|
|
| 22 |
text = ""
|
| 23 |
|
| 24 |
for i, segment in enumerate(segments):
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
text += transcription["text"] + " "
|
| 28 |
|
| 29 |
return text
|
|
|
|
| 8 |
|
| 9 |
audio = AudioSegment.from_mp3(audio_file)
|
| 10 |
segment_duration = 10 * 60 * 1000
|
| 11 |
+
num_segments = (len(audio) // segment_duration) + 1
|
| 12 |
|
| 13 |
segments = []
|
| 14 |
|
|
|
|
| 22 |
text = ""
|
| 23 |
|
| 24 |
for i, segment in enumerate(segments):
|
| 25 |
+
segment.export('./segment.mp3', format="mp3")
|
| 26 |
+
audio = open("./segment.mp3", 'rb')
|
| 27 |
+
transcription = client.audio.transcriptions.create(file=audio, language='es', model="whisper-1")
|
| 28 |
text += transcription["text"] + " "
|
| 29 |
|
| 30 |
return text
|