Spaces:
Runtime error
Runtime error
File size: 1,201 Bytes
7eb17c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import os
from backend.ai_processing.transcription import transcribe_audio_file_with_language
from backend.ai_processing.gpt import ai_language_detector
def process_audio(file_path: str) -> str:
"""
Processes the audio file by transcribing it and detecting its language.
- Takes the path to an audio file.
- Ensures the file exists.
- Uses the transcribe_audio_file_with_language function to transcribe the audio.
- Detects the language of the transcription.
- Raises FileNotFoundError if the file does not exist.
- Raises ValueError if the language cannot be detected (None).
- Returns the detected language as a string.
"""
if not os.path.exists(file_path):
raise FileNotFoundError(f"File {file_path} not found.")
transcription = transcribe_audio_file_with_language(file_path)
predicted_language = ai_language_detector(transcription)
if predicted_language is None:
raise ValueError("Language could not be detected.")
return predicted_language
if __name__ == "__main__":
# Example usage
file_path = "path/to/audio/file.wav"
transcription = process_audio(file_path)
print(transcription) |