1

Header is probably not clear enough to specify my issue, sorry for that. Im working on playing chess with speech recognition.

The issue:

Example: User is going to say "Rook A1 to A4" but, the speech recog thinks rook is "rogue" or "Brooklyn A1" etc.

How do i choose the spesific words like rook,pawn,queen etc. and make speech recog ai only understand those words ?

Current code i started with:

import pyttsx3
import speech_recognition as sr

recognizer = sr.Recognizer()

while True:

    try:

        with sr.Microphone() as mic:

            recognizer.adjust_for_ambient_noise(mic, duration=0.2)
            audio = recognizer.listen(mic)

            text = recognizer.recognize_google(audio)
            text = text.lower()

            print(f"{text}")

    except sr.UnknownValueError():
    
        recognizer = sr.Recognizer()
        continue
malcom32
  • 53
  • 1
  • 5
  • did you try keyword_entries? ```keyword_only_text = r.recognize_sphinx(audio, keyword_entries=[("rook",0.1),("knight",0.1),...])``` – Lukas Schmid May 10 '22 at 11:30
  • @LukasSchmid its for sure better than before, but dont understand whats the 0.1 for ? Can you clear a bit if u dont mind please ^^ – malcom32 May 10 '22 at 18:34

1 Answers1

2

You should use keyword_entries. Provide them as dictionary like so keyword_only_text = r.recognize_sphinx(audio, keyword_entries=[("rook",0.1),("knight",0.1),...])

This feature unfortunately is not available for recognize_google

The scalar values decide the sensitivity to that word. If you set them to one it will map any words recorded only to your words. If set to 0.001 you will only get a slight bias towards them.

See the workings of the function at speech_recognition/recognize_sphinx.

Lukas Schmid
  • 1,895
  • 1
  • 6
  • 18