import speech_recognition
from audioplayer import AudioPlayer
import gtts, os
sr = speech_recognition.Recognizer()
sr.pause_threshold = 0.5
while True:
with speech_recognition.Microphone() as mic:
sr.adjust_for_ambient_noise(source=mic, duration=0.5)
audio = sr.listen(source=mic)
query = sr.recognize_google(audio_data=audio, language="ru").lower()
t1 = gtts.gTTS(query, lang="ru")
t1.save("welcome.mp3")
print(query)
AudioPlayer("welcome.mp3").play(block=True)
os.remove("welcome.mp3")
keyword = "Проснись"
if target_word in query.split():
tts = gtts.gTTS(query, lang="ru")
tts.save("response.mp3")
AudioPlayer("response.mp3").play(block=True)
os.remove("response.mp3")