dynstat commited on
Commit
2f0cc23
·
verified ·
1 Parent(s): 3040779

Upload async_ai_voice.py

Browse files
Files changed (1) hide show
  1. async_ai_voice.py +24 -0
async_ai_voice.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ from typing import Dict, Any
3
+
4
+ # Initialize the transcription pipeline
5
+ transcriber = pipeline("automatic-speech-recognition", model="distil-whisper/distil-large-v3")
6
+
7
+ async def send_to_voice_AI(audio_data: bytes) -> Dict[str, Any]:
8
+ """
9
+ Transcribes audio data using the Hugging Face Whisper model.
10
+
11
+ Args:
12
+ audio_data (bytes): The raw audio data to be transcribed.
13
+
14
+ Returns:
15
+ Dict[str, Any]: A dictionary containing the transcription result or error message.
16
+ """
17
+ print("Transcribing audio")
18
+ try:
19
+ # Transcribe the audio
20
+ result = transcriber(audio_data)
21
+ return {"text": result["text"]}
22
+ except Exception as e:
23
+ print(f"Error during transcription: {str(e)}")
24
+ return {"text": "Sorry, an error occurred during transcription."}