Spaces:
Configuration error
Configuration error
Download async_ai_voice.py from dynstat/tgbotAIchat: direct link, hf CLI and curl.
- Browser
- Download file 859 Bytes
-
https://huggingface.co/spaces/dynstat/tgbotAIchat/resolve/main/async_ai_voice.py
- Command line
-
hf download hf://spaces/dynstat/tgbotAIchat/async_ai_voice.py
-
curl -L -o async_ai_voice.py https://huggingface.co/spaces/dynstat/tgbotAIchat/resolve/main/async_ai_voice.py
859 Bytes
| from transformers import pipeline | |
| from typing import Dict, Any | |
| # Initialize the transcription pipeline | |
| transcriber = pipeline("automatic-speech-recognition", model="distil-whisper/distil-large-v3") | |
| async def send_to_voice_AI(audio_data: bytes) -> Dict[str, Any]: | |
| """ | |
| Transcribes audio data using the Hugging Face Whisper model. | |
| Args: | |
| audio_data (bytes): The raw audio data to be transcribed. | |
| Returns: | |
| Dict[str, Any]: A dictionary containing the transcription result or error message. | |
| """ | |
| print("Transcribing audio") | |
| try: | |
| # Transcribe the audio | |
| result = transcriber(audio_data) | |
| return {"text": result["text"]} | |
| except Exception as e: | |
| print(f"Error during transcription: {str(e)}") | |
| return {"text": "Sorry, an error occurred during transcription."} |