Use raspberryPi and julus (speech recognition). ① Microphone Use julius (speech recognition) on raspberry Pi. ② Installation Use raspberry Pi and Julius (speech recognition). ③ Dictionary creation Use raspberry Pi and Julius (speech recognition). ④ L Chika Use raspberry Pi and Julius (speech recognition). ⑤ i2c character display
raspberryPi 3B+ USB microphone LED Resistance 220Ω Two jumper wires (male-female)
Go to the directory where you want to save it and prepare the code for socket communication with python.
$ sudo vim testnet001.py
testnet001.py
import socket
import time
HOST = '127.0.0.1' #IP address of julius server
PORT = 10500 #julius server listening port
DATESIZE = 1024 #Number of received data bytes
class Julius:
def __init__(self):
self.sock = None
def run(self):
#Connect to julius server with socket communication
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as self.sock:
self.sock.connect((HOST, PORT))
strTemp = "" #Variable to store spoken words
fin_flag = False #End of story flag
while True:
#Receive data from julius server
data = self.sock.recv(DATESIZE).decode('utf-8')
for line in data.split('\n'):
#From the received data<WORD>Extract the words written after and store them in a variable.
# <WORD>After, the spoken words are listed.
index = line.find('WORD="')
if index != -1:
#Store the words spoken in strTemp
strTemp = strTemp + line[index+6:line.find('"',index+6)]
#For received data</RECOGOUT>'If there is, the story ends ⇒ Set the flag to True
if '</RECOGOUT>' in line:
fin_flag = True
#Execute a print statement for each word spoken
if fin_flag == True:
if 'Thank you' in strTemp:
print("You are welcome")
elif 'Hello' in strTemp:
print("Good evening")
else:
print("Spoken words:" + strTemp)
fin_flag = False
strTemp = ""
if __name__ == "__main__":
julius = Julius()
julius.run()
Exit the editor after creating it. Call your own dictionary in module mode.
$ cd
$ julius -C ~/julius/julius-4.6/julius-kit/dictation-kit-4.5/am-gmm.jconf -nostrip -gram ~/julius/dict/test -input mic -module
Julius is waiting in module mode, so leave it as it is and launch another terminal.
$cd Python code destination directory
$ sudo python3 testnet001.py
If you talk and respond, socket communication is complete.
If you check the LED wiring, someone's article will come out, so omit it. The pin uses GPIO18.
testnet002.py
import RPi.GPIO as GPIO
import time
import socket
import string
def main():
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
for i in range(5):
GPIO.output(18, True)
time.sleep(0.1)
GPIO.output(18, False)
time.sleep(0.1)
GPIO.output(18, GPIO.LOW)
HOST = '127.0.0.1' #IP address of julius server
PORT = 10500 #julius server listening port
DATESIZE = 1024 #Number of received data bytes
class Julius:
def __init__(self):
self.sock = None
def run(self):
#Connect to julius server with socket communication
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as self.sock:
self.sock.connect((HOST, PORT))
strTemp = "" #Variable to store spoken words
fin_flag = False #End of story flag
while True:
#Receive data from julius server
data = self.sock.recv(DATESIZE).decode('utf-8')
for line in data.split('\n'):
#From the received data<WORD>Extract the words written after and store them in a variable.
# <WORD>After, the spoken words are listed.
index = line.find('WORD="')
if index != -1:
#Store the words spoken in strTemp
strTemp = strTemp + line[index+6:line.find('"',index+6)]
#For received data</RECOGOUT>'If there is, the story ends ⇒ Set the flag to True
if '</RECOGOUT>' in line:
fin_flag = True
#Execute a print statement for each word spoken
if fin_flag == True:
if 'Thank you' in strTemp:
print("You are welcome")
main()
elif 'Hello' in strTemp:
print("Good evening")
else:
print("Spoken words:" + strTemp)
fin_flag = False
strTemp = ""
if __name__ == "__main__":
julius = Julius()
julius.run()
It glows when called in module mode and the above code is executed in another terminal.
I was able to get Julius to work in module mode. Next, recognize the words and go to the i2c display display edition. Use raspberry Pi and Julius (speech recognition). ⑤ i2c character display
Recommended Posts