Download interface.py from SkillForge45/Maestro-Assistant-1.1-Base-0: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/SkillForge45/Maestro-Assistant-1.1-Base-0/resolve/main/interface.py
- Command line
-
hf download hf://SkillForge45/Maestro-Assistant-1.1-Base-0/interface.py
-
curl -L -o interface.py https://huggingface.co/SkillForge45/Maestro-Assistant-1.1-Base-0/resolve/main/interface.py
1.94 kB
| import speech_recognition as sr | |
| import pyttsx3 | |
| import pickle | |
| from model import MaestroAssistant | |
| class VoiceAssistant: | |
| def __init__(self): | |
| self.recognizer = sr.Recognizer() | |
| self.engine = pyttsx3.init() | |
| try: | |
| with open('maestro_model.pkl', 'rb') as f: | |
| self.assistant = pickle.load(f) | |
| except: | |
| self.assistant = MaestroAssistant() | |
| voices = self.engine.getProperty('voices') | |
| try: | |
| self.engine.setProperty('voice', voices[0].id) # Попытка русского | |
| except: | |
| pass | |
| self.engine.setProperty('rate', 150) | |
| def listen(self): | |
| with sr.Microphone() as source: | |
| print("Слушаю...") | |
| self.recognizer.adjust_for_ambient_noise(source) | |
| audio = self.recognizer.listen(source) | |
| try: | |
| text = self.recognizer.recognize_google(audio, language='ru-RU').lower() | |
| print(f"Распознано: {text}") | |
| return text | |
| except Exception as e: | |
| print(f"Ошибка распознавания: {e}") | |
| return "" | |
| def speak(self, text): | |
| print(f"Маэстро: {text}") | |
| self.engine.say(text) | |
| self.engine.runAndWait() | |
| def run(self): | |
| print("Ассистент Маэстро активирован! Говорите 'Эй Маэстро' для начала.") | |
| while True: | |
| text = self.listen() | |
| if text.startswith(self.assistant.wake_word): | |
| response = self.assistant.handle_command(text) | |
| if response: | |
| self.speak(response) | |
| else: | |
| self.speak("Не понял команду") | |
| if __name__ == "__main__": | |
| assistant = VoiceAssistant() | |
| assistant.run() |