I read all howtos and tutorials more often as I should... I think those are for developers and useres with experience.
Nevertheless I really want to get it to start so here are my questions.
I found a python prog that should start a aktion to a given string
my goal is to speak some french words to my rapserry 2 b+ and he does some aktion ...
example "luemiere s'il vous plait" he put the lights on
Plz help me and other newbies to get some little work done :)
best regards
#!/usr/bin/pythonfromosimportenviron,pathfrompocketsphinx.pocketsphinximport*fromsphinxbase.sphinxbaseimport*importpyaudioimportwaveimportsocketimporttime#pocketsphinx_continuous -adcdev sysdefault -hmm /usr/local/share/pocketsphinx/model/en-us/en-us -lm 9735.lm -dict 9735.dic -samprate 16000 -inmic yes#MODELDIR = "/usr/local/share/pocketsphinx/model"MODELDIR="/home/mentor/pocketsphinx-5prealpha/model"#modeldir = "/home/mentor/pocketsphinx-5prealpha/model"#DATADIR = "/home/perf/Downloads/TrevorWarren/Python/Dev/PocketSpinx_TTS/data"#DATADIR = "/home/mentor/pocketsphinx-5prealpha/test/data"DATADIR="/home/mentor/pocketsphinx-5prealpha/test/data"# Create a decoder with certain modelconfig=Decoder.default_config()config.set_string('-adcdev','sysdefault')#config.set_string('-adcdev', 'plughw:0,0')config.set_string('-hmm','/usr/local/share/pocketsphinx/model/en-us/en-us')config.set_string('-lm','/usr/local/share/pocketsphinx/model/de-deu/engwordlist/9615.lm')#config.set_string('-kws', '/home/perf/Downloads/TrevorWarren/Python/Dev/PocketSpinx_TTS/data/keywords')config.set_string('-dict','/usr/local/share/pocketsphinx/model/de-deu/engwordlist/9615.dic')config.set_string('-samprate','16000')config.set_string('-inmic','yes')#Specify recognition key phrase#config.set_string('-keyphrase', 'Open Garage')#config.set_float('-kws_threshold', 1e+20)# Hide the VERY verbose logging informationconfig.set_string('-logfn','/dev/null')decoder=Decoder(config)p=pyaudio.PyAudio()stream=p.open(format=pyaudio.paInt16,channels=1,rate=16000,input_device_index=1,input=True,output=False)#frames_per_buffer=256stream.start_stream()in_speech_bf=False#decoder.set_lm_file("lm", '/usr/local/share/pocketsphinx/model/en-us/en-us.lm.bin')#decoder.set_keyphrase("kws", "FORWARD")#decoder.set_search("kws")#decoder = Decoder(config)#decoder.start_utt()#print "Starting to listennnnn"decoder.start_utt()whileTrue:try:buf=stream.read(1024)ifbuf:decoder.process_raw(buf,False,False)ifdecoder.get_in_speech()!=in_speech_bf:in_speech_bf=decoder.get_in_speech()ifnotin_speech_bf:decoder.end_utt()res=decoder.hyp().hypstrprintresifres=="I AM FINE":print"Meuuuuuuuuuuh."decoder.start_utt()else:breakexcept:print"Meh."passdecoder.end_utt()
it works half .. it does the aktion i want(trigger on "I AM FINE") but there are some errors and i dont knew why he dont get the option "-inmic" for example or why he is alwas print MEH and why he does not want to close with STRG + C .....the outcame
You do not need ''-adcdev" and "-inmic" options for this script if I understand correctly what you are trying to acheive. I would suggest to follow this script
Also, ALSA errors can be fixed by commenting lines in the config as suggested here
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I already known the script and tried about 100 times the last 2 weeks, but now i got it running...
also big thanks for the not needed config parameters and the help to fix the also output.
so the scritp is working with french BUT it is not important what i say he always add that
"Detected keyphrase, restarting search" even if he knews it is not the keyword
#!/usr/bin/pythonimportsys,osfrompocketsphinx.pocketsphinximport*fromsphinxbase.sphinxbaseimport*#MODELDIR = "/usr/local/share/pocketsphinx/model"modeldir="/usr/local/share/pocketsphinx/model"#modeldir = "/home/mentor/pocketsphinx-5prealpha/model"datadir="/usr/local/share/pocketsphinx/test/data"config=Decoder.default_config()#config.set_string('-hmm', '/usr/local/share/pocketsphinx/model/en-us/en-us')#config.set_string('-lm', '/usr/local/share/pocketsphinx/model/de-deu/engwordlist/9615.lm')#config.set_string('-dict', '/usr/local/share/pocketsphinx/model/de-deu/engwordlist/9615.dic')config.set_string('-hmm','/usr/local/share/pocketsphinx/model/fr-fra/lium_french_f0')config.set_string('-lm','/usr/local/share/pocketsphinx/model/fr-fra/meinfrlm.lm')config.set_string('-dict','/usr/local/share/pocketsphinx/model/fr-fra/meinfrdic.dic')config.set_string('-samprate','16000')#config.set_string('-hmm', os.path.join(modeldir, 'en-us/en-us'))#config.set_string('-dict', os.path.join(modeldir, 'en-us/cmudict-en-us.dict'))config.set_string('-keyphrase','musique')config.set_float('-kws_threshold',1e+20)# Open file to read the data#stream = open(os.path.join(datadir, "goforward.raw"), "rb")# Alternatively you can read from microphoneimportpyaudio#p=pyaudio.PyAudio()stream=p.open(format=pyaudio.paInt16,channels=1,rate=16000,input=True,frames_per_buffer=1024)stream.start_stream()# Process audio chunk by chunk. On keyphrase detected perform action and restart searchdecoder=Decoder(config)decoder.start_utt()whileTrue:buf=stream.read(1024)ifbuf:decoder.process_raw(buf,False,False)else:breakifdecoder.hyp()!=None:print([(seg.word,seg.prob,seg.start_frame,seg.end_frame)forsegindecoder.seg()])print("Detected keyphrase, restarting search")decoder.end_utt()decoder.start_utt()
I get to the point that i notice that this is actual the important code that do the job after initialisation.
decoder.start_utt()
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
else:
break
if decoder.hyp() != None:
print ([(seg.word, seg.prob, seg.start_frame, seg.end_frame) for seg in decoder.seg()])
print ("Detected keyphrase, restarting search")
decoder.end_utt()
decoder.start_utt()
I need some help to understand this...
I comment the lienes with what i think they do
//decoder start that means it start pocketsphinx and wait for inputdecoder.start_utt()//as long the decodes is startedwhileTrue://read the streaming stuff in 1024 blocksbuf=stream.read(1024)//if there is something to read do itifbuf:decoder.process_raw(buf,False,False)//othewise dont readelse:break//if the hypothesis (the word that pocketsphinx thinks to have reconised) is not emptyifdecoder.hyp()!=None://this si actually I dont get !!! I think he prints out all infos he has about the reconised word print([(seg.word,seg.prob,seg.start_frame,seg.end_frame)forsegindecoder.seg()])//print this sentenceprint("Detected keyphrase, restarting search")//restart pocketsphinx engine that is the part that hear youdecoder.end_utt()decoder.start_utt()
big thanks
Last edit: justin case 2017-02-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I commented out the line "config.set_string('-lm', '/usr/local/share/pocketsphinx/model/fr-fra/meinfrlm.lm')" and it just works ! that is so awesome :) I will update the code here later.
(i searched for a donation link or upvote link for you but have nothing found.. so again big big thanks!)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
now i am trying to extend this with the switch code from Nickolay V. Shmyrev from xchange
btw near over 90% things about sphinx I ixquicked or duckduckgogoed are responed helpfull be him big thanks men!
this is actual what I have
#!/usr/bin/pythonimportsys,osfrompocketsphinx.pocketsphinximport*fromsphinxbase.sphinxbaseimport*importtimemodeldir="/usr/local/share/pocketsphinx/model"datadir="/usr/local/share/pocketsphinx/test/data"# Init decoderconfig=Decoder.default_config()config.set_string('-hmm','/usr/local/share/pocketsphinx/model/fr-fra/lium_french_f0')config.set_string('-dict','/usr/local/share/pocketsphinx/model/fr-fra/meinfrdic.dic')config.set_string('-logfn','/dev/null')decoder=Decoder(config)# Add searchesdecoder.set_kws('keyword','/usr/local/share/pocketsphinx/model/fr-fra/keyword.list')decoder.set_lm_file('lm','/usr/local/share/pocketsphinx/model/fr-fra/meinfrlm.lm')decoder.set_search('keyword')importpyaudiop=pyaudio.PyAudio()stream=p.open(format=pyaudio.paInt16,channels=1,rate=16000,input=True,frames_per_buffer=1024)stream.start_stream()in_speech_bf=Falsedecoder.start_utt()whileTrue:buf=stream.read(1024)ifbuf:decoder.process_raw(buf,False,False)ifdecoder.get_in_speech()!=in_speech_bf:in_speech_bf=decoder.get_in_speech()ifnotin_speech_bf:decoder.end_utt()print'first if'print'status decoder.get_search():',decoder.get_search()ifdecoder.get_search()=='keyword':print'second if'ifdecoder.hyp()!=None:print'Result:',decoder.hyp().hypstri=decoder.hyp().hypstr#haha = str(i)ifi=='salut vite ':print'333 if 'printidecoder.set_search('lm')print'lm mode active'time.sleep(1)# delays for 1 secondsifdecoder.hyp()!=None:print'last if schleife',decoder.hyp().hypstrifdecoder.hyp().hypstr=='musique':print'no soundplayer installed and what'elifdecoder.hyp().hypstr=='rapport':print'nothing new'elifdecoder.hyp().hypstr=='changes musique':print'how to change nothing'elifdecoder.hyp().hypstr=='tuez google':print'ping -c 5 www.google.com'else:print'DECODER EMPTY'else:decoder.set_search('keyword')print'keywordfuck'decoder.start_utt()else:breakdecoder.end_utt()
what i have done.. i started it say something wrong ... said trigger word "salut vite " then said "musique" this was in this cicle "lm mode active
DECODER EMPTY
first if
status decoder.get_search(): lm
keywordfuck"
then i triggered "salut vite" again and he takes the musique from last call and triggers it
so I have to say "salut vite" say "musique" and then again "salut vite" so that the musique is actual triggered.
I really cant out find why he need a second "salut vite" I am so close for finishing .....
best regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi after hours I finally found my stupid fault....... it have to be in the else area so in the reloop it has the lm alrdy opened.
the code works actually under raspbian jessie python 2.7.8
#!/usr/bin/pythonimportsys,osfrompocketsphinx.pocketsphinximport*fromsphinxbase.sphinxbaseimport*importtimemodeldir="/usr/local/share/pocketsphinx/model"datadir="/usr/local/share/pocketsphinx/test/data"# Init decoderconfig=Decoder.default_config()config.set_string('-hmm','/usr/local/share/pocketsphinx/model/fr-fra/lium_french_f0')config.set_string('-dict','/usr/local/share/pocketsphinx/model/fr-fra/meinfrdic.dic')config.set_string('-logfn','/dev/null')decoder=Decoder(config)# Add searchesdecoder.set_kws('keyword','/usr/local/share/pocketsphinx/model/fr-fra/keyword.list')decoder.set_lm_file('lm','/usr/local/share/pocketsphinx/model/fr-fra/meinfrlm.lm')decoder.set_search('keyword')importpyaudiop=pyaudio.PyAudio()stream=p.open(format=pyaudio.paInt16,channels=1,rate=16000,input=True,frames_per_buffer$stream.start_stream()in_speech_bf=Falsedecoder.start_utt()whileTrue:buf=stream.read(1024)ifbuf:decoder.process_raw(buf,False,False)ifdecoder.get_in_speech()!=in_speech_bf:in_speech_bf=decoder.get_in_speech()ifnotin_speech_bf:decoder.end_utt()print'first if'print'status decoder.get_search():',decoder.get_search()ifdecoder.get_search()=='keyword':print'second if'ifdecoder.hyp()!=None:print'Result:',decoder.hyp().hypstri=decoder.hyp().hypstrifi=='salut vite ':print'333 if 'printidecoder.set_search('lm')print'lm mode active'time.sleep(1)# delays for 1 secondsprinti# it is alrdy empty here print decoder.hyp().hypstrprint'after sleep ops'else:print'else'printdecoder.hyp().hypstrifdecoder.hyp().hypstr=='musique':print'no soundplayer installed and what'elifdecoder.hyp().hypstr=='rapport':print'nothing new'elifdecoder.hyp().hypstr=='changes musique':print'how to change nothing'elifdecoder.hyp().hypstr=='computer':print'42'elifdecoder.hyp().hypstr=='tuez google':print'contacting skynet'decoder.set_search('keyword')print'keywordfuck'decoder.start_utt()else:breakdecoder.end_utt()
at first it is keywordmode i trigger lm mode with "salut vite" attention the space in if == 'salut vite ' is important ...why ever then in lm mode I can trigger actions with a word or more words. here i called
"rapport" "computer" and "musique" after the ONE command it goes to keyword mode so I have to activate it again with "salut vite"
Big thanks to all thats was a huge boost for me :) i hope i can help someone too with this ...
Last edit: justin case 2017-02-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
SOLVED LAST POST
Hello communtiy,
First of all.. I am a newbie and dont knew much.
I read all howtos and tutorials more often as I should... I think those are for developers and useres with experience.
Nevertheless I really want to get it to start so here are my questions.
I found a python prog that should start a aktion to a given string
my goal is to speak some french words to my rapserry 2 b+ and he does some aktion ...
example "luemiere s'il vous plait" he put the lights on
Plz help me and other newbies to get some little work done :)
best regards
it works half .. it does the aktion i want(trigger on "I AM FINE") but there are some errors and i dont knew why he dont get the option "-inmic" for example or why he is alwas print MEH and why he does not want to close with STRG + C .....the outcame
So I try to adept this to french
but with french it doesnt work at all here is the outcome...
If i start it directly it works....
sudo pocketsphinx_continuous -hmm /usr/local/share/pocketsphinx/model/fr-fra/lium_french_f0 -lm /usr/local/share/pocketsphinx/model/fr-fra/fr-small.lm.n -dict /usr/local/share/pocketsphinx/model/fr-fra/myselffr.dic -samprate 16000/8000/48000 -inmic yes
Last edit: justin case 2017-02-19
You do not need ''-adcdev" and "-inmic" options for this script if I understand correctly what you are trying to acheive. I would suggest to follow this script
Also, ALSA errors can be fixed by commenting lines in the config as suggested here
Big thanks to you.
I already known the script and tried about 100 times the last 2 weeks, but now i got it running...
also big thanks for the not needed config parameters and the help to fix the also output.
so the scritp is working with french BUT it is not important what i say he always add that
"Detected keyphrase, restarting search" even if he knews it is not the keyword
like (the keyword ist "musique")
"INFO: cmn_live.c(88): Update from < 5.76 0.28 0.11 0.01 -0.28 -0.18 -0.02 -0.16 -0.10 -0.14 -0.08 -0.11 -0.13 >
INFO: cmn_live.c(105): Update to < 5.64 0.27 0.12 0.00 -0.27 -0.16 -0.02 -0.15 -0.10 -0.15 -0.08 -0.11 -0.13 >
0, 8049, 8077), ('<sil>', 0, 8078, 8102), ('computer', 0, 8103, 8149)]
Detected keyphrase, restarting search"</sil>
the code
the outcome
I get to the point that i notice that this is actual the important code that do the job after initialisation.
I need some help to understand this...
I comment the lienes with what i think they do
big thanks
Last edit: justin case 2017-02-16
It is better to use cmusphinx-fr-5.2
lm recognition is conflicting with keyphrase, you need to remove this line. It was not present in original kws example too.
such a fast answer. big thanks to you too!
I commented out the line "config.set_string('-lm', '/usr/local/share/pocketsphinx/model/fr-fra/meinfrlm.lm')" and it just works ! that is so awesome :) I will update the code here later.
(i searched for a donation link or upvote link for you but have nothing found.. so again big big thanks!)
so here it is.. big thanks for help this is actual working.. i cant change the topic heaer to solved :*(
outcame
now i am trying to extend this with the switch code from Nickolay V. Shmyrev from xchange
btw near over 90% things about sphinx I ixquicked or duckduckgogoed are responed helpfull be him big thanks men!
this is actual what I have
the outcame
what i have done.. i started it say something wrong ... said trigger word "salut vite " then said "musique" this was in this cicle "lm mode active
DECODER EMPTY
first if
status decoder.get_search(): lm
keywordfuck"
then i triggered "salut vite" again and he takes the musique from last call and triggers it
so I have to say "salut vite" say "musique" and then again "salut vite" so that the musique is actual triggered.
I really cant out find why he need a second "salut vite" I am so close for finishing .....
best regards
Hi after hours I finally found my stupid fault....... it have to be in the else area so in the reloop it has the lm alrdy opened.
the code works actually under raspbian jessie python 2.7.8
and here is the outcame
at first it is keywordmode i trigger lm mode with "salut vite" attention the space in if == 'salut vite ' is important ...why ever then in lm mode I can trigger actions with a word or more words. here i called
"rapport" "computer" and "musique" after the ONE command it goes to keyword mode so I have to activate it again with "salut vite"
Big thanks to all thats was a huge boost for me :) i hope i can help someone too with this ...
Last edit: justin case 2017-02-19