6

I am making a spoken PygLatin translator. A very basic one at least that tells one translated word.

If I speak more than one word, it get's all jumbled up and takes the first character in the first word and puts it onto the last spoken word with "ay" at the end.

So I have been having a few issues because of that. Is there a way to get it to stop listening after only one spoken word? Would there possibly be a way to also get the first letter of each word put to the end of each spoken word followed by "ay"?

here is a sample of my code so far:

import time
import speech_recognition as sr
from gtts import gTTS
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
from pygame import mixer
mixer.init()
pyg = "ay" 
count = 3
while count > 0:
    while (True == True):
  # get audio input
        original = sr.Recognizer()
        with sr.Microphone() as source:
      # listen for 1 second and create the ambient noise energy level
            original.adjust_for_ambient_noise(source, duration = 1)
            print("Say ONE word. If you do not wish to use the translator, say 'stop' ")
        audio = original.listen(source,phrase_time_limit = 1)

  # speech recognition with Google
        try:
            response = original.recognize_google(audio)
            if response == "stop":
                print("Thanks for using the PygLatin Translator, Goodbye!")
                break
                pyg_word = response + pyg
                w = response + pyg
                pyg_word = w[1 : len(pyg_word)]
                print(pyg_word)
                tts = gTTS(text = str(pyg_word), lang='en')
                tts.save("response.mp3")
                mixer.music.load('response.mp3')
                mixer.music.play()


        except sr.UnknownValueError:
            print("Translator could not understand audio")
        except sr.RequestError as e:
            print("Sphinx error; {0}".format(e))
Anwar Azeez
  • 101
  • 4

0 Answers0