Spaces:
Sleeping
Sleeping
Download voice_det.py from evildeity/HackOdisha: direct link, hf CLI and curl.
- Browser
- Download file 804 Bytes
-
https://huggingface.co/spaces/evildeity/HackOdisha/resolve/main/voice_det.py
- Command line
-
hf download hf://spaces/evildeity/HackOdisha/voice_det.py
-
curl -L -o voice_det.py https://huggingface.co/spaces/evildeity/HackOdisha/resolve/main/voice_det.py
804 Bytes
| import whisper | |
| from transformers import pipeline | |
| class Voice_Analysis: | |
| def __init__(self, emotion_model="prithivMLmods/Speech-Emotion-Classification", whisper_size="base"): | |
| # HF pipeline for speech emotion | |
| self.classifier = pipeline( | |
| "audio-classification", | |
| model=emotion_model, | |
| feature_extractor=emotion_model | |
| ) | |
| # Whisper for ASR | |
| self.modelwa = whisper.load_model(whisper_size) | |
| def detect(self, path): | |
| """Run emotion classification on an audio file. Returns list of dicts with label/score.""" | |
| return self.classifier(path) | |
| def subtitles(self, path): | |
| """Transcribe audio to text using Whisper.""" | |
| result = self.modelwa.transcribe(path) | |
| return result.get("text", "").strip() | |