HassenE22's picture
Upload folder using huggingface_hub
7eb17c5 verified
Raw
History Blame Contribute Delete
1.2 kB
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)