Spaces:
Runtime error
Runtime error
Download functions/backend/ai_processing/process_audio.py from HassenE22/AI_Language_Detector: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/HassenE22/AI_Language_Detector/resolve/main/functions/backend/ai_processing/process_audio.py
- Command line
-
hf download hf://spaces/HassenE22/AI_Language_Detector/functions/backend/ai_processing/process_audio.py
-
curl -L -o process_audio.py https://huggingface.co/spaces/HassenE22/AI_Language_Detector/resolve/main/functions/backend/ai_processing/process_audio.py
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) |