Jul-09-2022, 03:39 PM
Hello,
Something i never understood if why with an if and else statement there is that repeat effect.
Inside the try except the voice is saying "le fruit a été ajouté dans le panier" if its fraise or pomme word and saying "le légume a été ajouté au panier" if its a vegetable.
Why is it jumping to the else if there is no vegetable?
Something i never understood if why with an if and else statement there is that repeat effect.
Inside the try except the voice is saying "le fruit a été ajouté dans le panier" if its fraise or pomme word and saying "le légume a été ajouté au panier" if its a vegetable.
Why is it jumping to the else if there is no vegetable?
from speech_recognition import Recognizer, Microphone from gtts import gTTS import subprocess recognizer = Recognizer() # On enregistre le son with Microphone() as source: print("Réglage du bruit ambiant... Patientez...") recognizer.adjust_for_ambient_noise(source) print("Vous pouvez parler...") recorded_audio = recognizer.listen(source) print("Enregistrement terminé !") # Reconnaissance de l'audio try: print("Reconnaissance du texte...") text = recognizer.recognize_google( recorded_audio, language="fr-FR" ) print("Vous avez dit : {}".format(text)) hotword= ["pomme","fraise"] for h in hotword: if h in text: tts = gTTS(u"le fruit a été ajouté dans le panier", lang="fr") tts.save('out.mp3') cmd = ['mpg321', '-q', 'out.mp3'] subprocess.call(cmd) else: tts = gTTS(u"le légume a été ajouté au panier", lang="fr") tts.save('out.mp3') cmd = ['mpg321', '-q', 'out.mp3'] subprocess.call(cmd) except Exception as ex: print(ex)Thank you