Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if else repeating
#1
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?

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
Reply


Messages In This Thread
if else repeating - by Frankduc - Jul-09-2022, 03:39 PM
RE: if else repeating - by Gribouillis - Jul-09-2022, 04:06 PM
RE: if else repeating - by Frankduc - Jul-09-2022, 04:29 PM
RE: if else repeating - by deanhystad - Jul-09-2022, 08:55 PM
RE: if else repeating - by Frankduc - Jul-10-2022, 02:43 PM
RE: if else repeating - by deanhystad - Jul-10-2022, 05:57 PM
RE: if else repeating - by Frankduc - Jul-11-2022, 02:26 PM
RE: if else repeating - by ndc85430 - Jul-11-2022, 02:47 PM
RE: if else repeating - by Frankduc - Jul-11-2022, 08:28 PM
RE: if else repeating - by deanhystad - Jul-12-2022, 01:57 AM
RE: if else repeating - by Frankduc - Jul-12-2022, 07:50 PM
RE: if else repeating - by deanhystad - Jul-13-2022, 09:47 AM
RE: if else repeating - by Frankduc - Jul-14-2022, 12:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is 2/3 not just .666 repeating? DocFro 4 817 Dec-12-2023, 09:09 AM
Last Post: buran
  repeating a user_input astral_travel 17 2,497 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  factorial, repeating Aldiyar 4 2,897 Sep-01-2020, 05:22 PM
Last Post: DPaul
  Repeating equations Tbot100 2 3,342 May-29-2019, 02:38 AM
Last Post: heiner55
  repeating for loop Kaldesyvon 5 3,963 Dec-06-2018, 08:00 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020