[PYTHON] Use raspberry Pi and Julius (speech recognition). ③ Dictionary creation

Related article

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

Creating a dictionary file This was also very difficult.

Creating a file with reading kana for words (.yomi)

First, create a directory for creating a dictionary file.

$ cd julius
$ mkdr dict
$ cd dict

The hierarchy looks like this.

~/julius
    |--dict
    |--julius-4.6
          |--julius-kit
                |--dictation-kit-4.5
                |--grammer-kit-4.3.1

Use the vim command to create and edit files. Install vim.

$ apt-get install vim
$ vim --version

image.png Create a reading kana file

$ sudo vim test.yomi

Click the keyboard mark on the upper right to enable Japanese input. image.png ↓↓ image.png

Word → tab → reading kana (hiragana) I will write below. The word can be kanji. Be careful not to insert extra spaces as it will cause an error. Do not start a new line after entering the last word. Be careful not to empty the last line. image.png

When you have a wordbook, quit the vim editor with ctrl + C → ZZ. See this article for how to use vim. Frequently used Vim command summary

Convert the reading kana file to a romaji file (.phone) (.dic) I was addicted to this next code. It seems that there is no need for conversion after Julius 4.5.
$ sudo iconv -f utf8 -t eucjp

So run it with the following code.

$ perl ~/julius/julius-4.6/gramtools/yomi2voca/yomi2voca.pl test.yomi > ~/julius/dict/test.phone

Since it is not displayed in the terminal, check that the file is created and display it.

$ ls
$ sudo vim test.phone

image.png It's OK if the .yomi file is converted to romaji, so close it without touching it.

Create a grammar file (.grammar) ``` $ sudo vim test.grammar ``` Write the following code in the editor that opens. Write as many words as you have. Be careful to match the Roman alphabet in the .phone file. Example) ✕ KONNNITIHA 〇KONNICHIWA
S : NS_B TEST NS_E
TEST:ARIGATOU
TEST:KONNICHIWA

The S part on the first line of the syntax file shows the syntax definition, NS_B is the beginning of the sentence, and NS_E is the end of the sentence. The TEST part on the second and subsequent lines is a character string to be recognized, and the reading of the "phoneme" file (hello.phone) generated earlier is capitalized. Partially modified and quoted

image.png

Exit the editor after writing.

Create a vocabulary file (.voca) Create a vocabulary file by copying the .phone file. Edit the vocabulary file.
$ sudo cp test.phone test.voca
$ sudo vim test.voca

Align the format for each word and add it so that it has the following code format. The word and the romaji are separated by a tab, and it worked as it is, but it seems better to make it a space.

% ARIGATOU
Thank you a r i g a t o u
% KONNICHIHA
Hello k o N n i ch i w a
% NS_B
[s] silB
% NS_E
[/s] silE

image.png

Convert to dictionary data Move the directory.
$ cd julius/julius-4.6/gramtools/mkdfa

Execute the following code at the destination.

$ mkdfa.pl ~/julius/dict/test

If successful, ".dfa", ".term" and ".dict" files will be generated in the dict file. (For some reason, a file called .dfatmp was created, so I renamed it. The .tmp file was also created abruptly, but I'm not sure, so I left it.) image.png

Speech recognition using a dictionary
$ cd

Execute the following code.

$ julius -C ~/julius/julius-4.6/julius-kit/dictation-kit-4.5/am-gmm.jconf -nostrip -gram ~/julius/dict/test -input mic

image.png image.png

Also recognizes what you say "Thank you", "Hello" just a intently. did it.

Completion of creation of original dictionary Next, recognize the words and go to the L Chika edition. [Use raspberry Pi and Julius (speech recognition). ④ L Chika](https://qiita.com/chiapis2/items/a2ed64414c9e49b6cb42)

Reference [Raspberry Pi Day 4 ①: Create your own dictionary with Julius](https://kihara0223.hatenablog.com/entry/2020/01/04/111100) [Make specific words recognized by Raspberry Pi and Julius](https://www.pc-koubou.jp/magazine/19743) [Voice recognition using julius on Raspberry Pi](https://www.raspberrypirulo.net/entry/julius) []() []() [Voice recognition using julius4.5 on raspberry pi, garbled characters](https://teratail.com/questions/275012) [Frequently used Vim command summary](https://qiita.com/hide/items/5bfe5b322872c61a6896)

Recommended Posts

Use raspberry Pi and Julius (speech recognition). ③ Dictionary creation
Use raspberryPi and julius (speech recognition). ① Microphone edition
Use raspberryPi and Julius (speech recognition). ④ L Chika
Use julius (speech recognition) on raspberryPi. ② Installation
Raspberry Pi 3 x Julius (reading file and grammar file)
Use NeoPixel on Raspberry Pi
Use raspberryPi and julius (speech recognition). ① Microphone edition
Use raspberryPi and Julius (speech recognition). ④ L Chika
Use julius (speech recognition) on raspberryPi. ② Installation
Use raspberry Pi and Julius (speech recognition). ③ Dictionary creation
Speech synthesis and speech recognition by Microsoft Project Oxford
Use vl53l0x with Raspberry Pi (python)
MQTT on Raspberry Pi and Mac
Voice authentication & transcription with Raspberry Pi 3 x Julius x Watson (Speech to Text)
Pet monitoring with Rekognition and Raspberry pi
Use the Grove sensor on the Raspberry Pi
Use PIR motion sensor with raspberry Pi
Use Raspberry Pi Python to TMP36 analog temperature sensor and MCP3008 AD converter
Speech synthesis and speech recognition by Microsoft Project Oxford
How to use Raspberry Pi pie camera Python
MQTT RC car with Arduino and Raspberry Pi
Use Majoca Iris elongated LCD with Raspberry Pi
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Easy connection between Raspberry Pi and AWS IoT
Get temperature and humidity with DHT11 and Raspberry Pi
Raspberry Pi and AWS IoT connection program example
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a web server --3. Use MySQL