FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

Google Voice Kitを使ってみる(3. 音声→文字を認識するアプリケーションの作成)

Google Voice Kitを使ってみる、続き。 前回、アプリケーションが動作するようになったので、自分で音声認識のプログラムなどを作ってみたい。

以下のサイトを参考にして、プログラムを作成した。ちなみ、Google Speech APIを使用するために課金の情報を入力する必要がある。 1年間の無料評価ライセンスがあるのでそれを使用しているが、1年間の間にちゃんとしっかり活用しないとなあ。。。

aiyprojects.withgoogle.com

  • /home/pi/src/motion.py
#!/usr/bin/env python3

import aiy.audio
import aiy.cloudspeech
import aiy.voicehat

def main():
    '''Start voice recognition when motion is detected.'''
    button = aiy.voicehat.get_button() 
    recognizer = aiy.cloudspeech.get_recognizer()
    recognizer.expect_phrase('repeat after me')
    aiy.audio.get_recorder().start()
    while True:
        print('Press the button and speak')
        button.wait_for_press() 
        print('Listening ...') 
        text = recognizer.recognize()  # 音声認識を実行する。
        print(text)
        aiy.audio.say('You said ')
        aiy.audio.say(text)

if __name__ == '__main__':
    main()

サンプルプログラムにはaiy.audio.say('You said ', text)と書いてあるが、実行中にエラーメッセージが出てしまうので修正しなければならなかった。

Press the button and speak
Listening ...
repeat after me
Unknown language: repeat after me
Valid languages:
en-US
en-GB
de-DE
es-ES
fr-FR
it-IT

Usage: pico2wave <words>
  -w, --wave=filename.wav     Write output to this WAV file (extension SHOULD be .wav)
  -l, --lang=lang             Language (default: "en-US")

Help options:
  -?, --help                  Show this help message
      --usage                 Display brief usage message
Traceback (most recent call last):
  File "./src/motion.py", line 22, in <module>
    main()
  File "./src/motion.py", line 19, in main
    aiy.audio.say('You said ', text)

これを実行して、音声認識を実行する。

$ ./src/motion.py 
Press the button and speak
Listening ...
what time is it now     # 認識結果
Press the button and speak
Listening ...

ある程度きちんと認識できる。ただし、"Turn on the light", "Turn off the light" の「ターン」の発音が下手くそすぎて認識されない。 スマートフォンGoogleに喋らせるとうまく認識するので、これは日本人の発音の問題かなあ。 日本語のAPIがきちんと使えるようになればいいのだが。

f:id:msyksphinz:20171224232547p:plain

アプリケーション実行中はボタンのLEDが点灯する。格好いい。

関連記事