Spaces:
Sleeping
Sleeping
Delete main.py
Browse files
main.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
|
2 |
-
import speech_recognition as sr
|
3 |
-
from transformers import pipeline
|
4 |
-
import edge_tts
|
5 |
-
import asyncio
|
6 |
-
|
7 |
-
# Load Whisper model
|
8 |
-
asr = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
9 |
-
|
10 |
-
# Load translation model (Yoruba → English)
|
11 |
-
from transformers import MarianMTModel, MarianTokenizer
|
12 |
-
mt_model_name = "Helsinki-NLP/opus-mt-yo-en"
|
13 |
-
tokenizer = MarianTokenizer.from_pretrained(mt_model_name)
|
14 |
-
model = MarianMTModel.from_pretrained(mt_model_name)
|
15 |
-
|
16 |
-
# TTS
|
17 |
-
async def speak(text):
|
18 |
-
communicate = edge_tts.Communicate(text, "en-US-GuyNeural")
|
19 |
-
await communicate.save("output.mp3")
|
20 |
-
|
21 |
-
def translate_text(text):
|
22 |
-
inputs = tokenizer(text, return_tensors="pt", padding=True)
|
23 |
-
translated = model.generate(**inputs)
|
24 |
-
return tokenizer.decode(translated[0], skip_special_tokens=True)
|
25 |
-
|
26 |
-
# Real-time mic input
|
27 |
-
recognizer = sr.Recognizer()
|
28 |
-
with sr.Microphone() as source:
|
29 |
-
print("Speak now...")
|
30 |
-
audio = recognizer.listen(source)
|
31 |
-
print("Processing...")
|
32 |
-
|
33 |
-
# Speech to Text
|
34 |
-
result = asr(audio.get_wav_data())["text"]
|
35 |
-
print("Transcribed:", result)
|
36 |
-
|
37 |
-
# Translate
|
38 |
-
translation = translate_text(result)
|
39 |
-
print("Translated:", translation)
|
40 |
-
|
41 |
-
# Speak
|
42 |
-
asyncio.run(speak(translation))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|