5

There is this awesome threat, showing how to use the say-command from mac within python: Python Text to Speech in Macintosh

Is there anything similar for the speech-recognition? I would like to use the german speech-recognition from mac to get a user-input.

Other possible answer for this question would be a speech-recognition within python for german-languages.

Best

Community
  • 1
  • 1
Christoph Müller
  • 483
  • 1
  • 5
  • 16

2 Answers2

5

This would work and the SpeechRecognition package will handle German

import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
   audio = r.listen(source)
SAMO
  • 458
  • 1
  • 3
  • 20
  • 1
    Thank you very much for your quick answer. Unfortunately it does not work for me in this way. I do get the error message: Traceback (most recent call last): File "sp.py", line 1, in import SpeechRecognition as sr ImportError: No module named SpeechRecognition The library is installed and the minimal-example works fine. Why would it work in german? How to you tell pyhton to change language? – Christoph Müller Jun 27 '16 at 18:51
  • Incredibly sorry I had the package name wrong, thats my bad. It should work now. And SpeechRecognition supports like 188 different languages. Check it out here: https://pypi.python.org/pypi/SpeechRecognition/ – SAMO Jun 27 '16 at 18:54
  • sorry, but one question left: How do i change to german language? Do i have to install the language-package for pocketsquinx for example? Is there an easy way, maybe via pip? – Christoph Müller Jun 27 '16 at 19:03
  • No problem at all. You o have to install pocket-sphinx, but from that point on you just specify the language you want to use. – SAMO Jun 27 '16 at 19:05
  • Sorry to bother again, but i don't get this running. When downloading the official language-pack and run the sh, I do get following error-message: ERROR: "pocketsphinx.c", line 134: Failed to find mdef file inside the model folder specified with -hmm 'model_parameters/voxforge.cd_cont_4000' INFO: feat.c(713): Initializing feature stream to type: '1s_c_d_dd', ceplen=13, CMN='current', VARNORM='no', AGC='none' INFO: cmn.c(142): mean[0]= 12.00, mean[1..12]= 0.0 ERROR: "acmod.c", line 87: Folder 'model_parameters/voxforge.cd_cont_4000' does not contain acoustic model definition 'mdef' – Christoph Müller Jun 27 '16 at 20:29
  • Pocketsphinx does not support German well, you'd better use Google backend – Nikolay Shmyrev Jun 27 '16 at 21:29
1

Great! Thanks for your help. To use google with german, simply add language="de"

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

print("Google Speech Recognition thinks you said " + r.recognize_google(audio, language="de"))
Christoph Müller
  • 483
  • 1
  • 5
  • 16