| import assemblyai as aai |
|
|
| aai.settings.api_key = "2c02e1bdab874068bdcfb2e226f048a4" |
|
|
| def transcribe_audio(file_path: str, model_size=None) -> tuple[str, str, float]: |
| print(f"Transcribing audio file: {file_path} with language detection") |
|
|
| config = aai.TranscriptionConfig( |
| speech_model=aai.SpeechModel.nano, |
| language_detection=True, |
| language_confidence_threshold=0.4 |
| ) |
|
|
| transcriber = aai.Transcriber() |
|
|
| transcript = transcriber.transcribe(file_path, config) |
|
|
| if transcript.status == "error": |
| raise RuntimeError(f"Transcription failed: {transcript.error}") |
|
|
| |
| response = transcript.json_response |
| language = response.get("language_code") |
| confidence = response.get("language_confidence") |
| |
| result = { |
| "transcript": transcript.text, |
| "language": language, |
| "confidence": confidence |
| } |
| |
| return transcript.text, language, confidence |