Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,19 +6,31 @@ import os
|
|
| 6 |
openai.api_key = os.getenv('API_KEY')
|
| 7 |
|
| 8 |
def transcribe_audio(file_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Open the wav file
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Extract the transcription text
|
| 18 |
transcription_text = response['text']
|
| 19 |
return transcription_text
|
| 20 |
|
| 21 |
def transcribe_and_display(audio_path):
|
|
|
|
|
|
|
|
|
|
| 22 |
# Transcribe the audio file
|
| 23 |
transcription = transcribe_audio(audio_path)
|
| 24 |
return transcription
|
|
|
|
| 6 |
openai.api_key = os.getenv('API_KEY')
|
| 7 |
|
| 8 |
def transcribe_audio(file_path):
|
| 9 |
+
if file_path is None:
|
| 10 |
+
return "Error: No file path provided."
|
| 11 |
+
|
| 12 |
+
# Debugging: Print the file path
|
| 13 |
+
print(f"Received file path: {file_path}")
|
| 14 |
+
|
| 15 |
# Open the wav file
|
| 16 |
+
try:
|
| 17 |
+
with open(file_path, 'rb') as audio_file:
|
| 18 |
+
response = openai.Audio.transcriptions.create(
|
| 19 |
+
model="whisper-1", # specify the appropriate model for transcription
|
| 20 |
+
file=audio_file,
|
| 21 |
+
language='ta' # specify 'ta' for Tamil language
|
| 22 |
+
)
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"Error during transcription: {e}"
|
| 25 |
|
| 26 |
# Extract the transcription text
|
| 27 |
transcription_text = response['text']
|
| 28 |
return transcription_text
|
| 29 |
|
| 30 |
def transcribe_and_display(audio_path):
|
| 31 |
+
# Debugging: Print the audio path
|
| 32 |
+
print(f"Received audio path: {audio_path}")
|
| 33 |
+
|
| 34 |
# Transcribe the audio file
|
| 35 |
transcription = transcribe_audio(audio_path)
|
| 36 |
return transcription
|