dreamers-blog
dreamers-blog

Reputation: 114

How can a python program recognize letter by letter instead of words using Speech Recognition?

I'm writing a Python program for blind people to help them write and read emails.

They can write an email vocally and listen to the emails they have not yet read as a speech (gTTS).

If the user chooses to write an email, they must spell out the receiver's email address vocally letter by letter instead of words or phrases to avoid any mistakes.

For example, with "[email protected]", I want the program to listen to one letter/character at a time, which means: "x", "y", "z", "@", "g", "m", "a", "i", "l", ".", "c", "o", "m" so it can add them together to reform the email address.

When I try to pronounce a letter it recognizes a word.

How can I have it recognize a letter instead of a word?

Here's the code:

    import audioop
    import pyaudio
    import wave
    from gtts import gTTS
    import speech_recognition as sr
    import os
    import email, smtplib, ssl


    r = sr.Recognizer()
    r.energy_threshold=4000

    def say(text):
      mytext = text
      language = 'en'
      myobj = gTTS(text=mytext, lang=language, slow=False)
      myobj.save("text_to_audio.mp3")
      os.system("afplay 'text_to_audio.mp3'")

    def listen_to_user():
      with sr.Microphone() as source:
       audio2=r.listen(source, timeout=0)
       return(str(r.recognize_google(audio2,language ="en-US", 
    show_all=False)))

    say("you chose to write an email")
    say("What's the receiver's email address?")
    receiver_email_address=listen_to_user()
    print(receiver_email_address) 
    say(receiver_email_address)
    say("is this correct?")
    answer=listen_to_user()

Upvotes: 1

Views: 1718

Answers (2)

modernonline
modernonline

Reputation: 1

My shallow hack was to split letters into small files, recording one letter at each time. However, even then "C" sometimes becomes "see" etc.

Upvotes: 0

Redgar Tech
Redgar Tech

Reputation: 365

Unfortunately, this isn't going to work as you hoped. With the regular google speech to text, you can most likely do single letters like 'H' 'I" "M" "O" "M" but you would require a machine learning algorithm that can detect special characters like @ or % by saying "percent sign" or "at symbol". If you do some more research, I'm sure you can do it.

Upvotes: 1

Related Questions