3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google AsisstantやAlexaに頼らないオリジナルスマートスピーカーの作り方 -応用・発展編-

Last updated at Posted at 2020-01-31

前回の記事でオリジナルのスマートスピーカーを作ることが出来ました。この状態でも充分使うことが出来ますが、改良こそがオリジナルスマートスピーカーの醍醐味です。改良例をいくつか紹介したいと思います。

ちなみに前回の時点でディレクトリ構造は以下のようになっているはずです。

├── audio
│   ├── output.wav
│   └── speak.wav
├── com
│   ├── __init__.py
│   ├── __pycache__
│   │   └── __init__.cpython-37.pyc
│   └── amivoice
│       ├── __init__.py
│       ├── __pycache__
│       │   └── __init__.cpython-37.pyc
│       └── wrp
│           ├── Wrp.py
│           ├── WrpListener.py
│           ├── Wrp_.py
│           ├── __init__.py
│           └── __pycache__
│               ├── Wrp.cpython-37.pyc
│               ├── WrpListener.cpython-37.pyc
│               └── __init__.cpython-37.pyc
├── curl-ca-bundle.crt
├── respeaker
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-37.pyc
│   │   ├── fft.cpython-37.pyc
│   │   ├── microphone.cpython-37.pyc
│   │   ├── pixel_ring.cpython-37.pyc
│   │   ├── player.cpython-37.pyc
│   │   ├── spectrum_analyzer.cpython-37.pyc
│   │   ├── spi.cpython-37.pyc
│   │   └── vad.cpython-37.pyc
│   ├── bing_speech_api.py
│   ├── fft.py
│   ├── gpio.py
│   ├── microphone.py
│   ├── pixel_ring.py
│   ├── player.py
│   ├── pocketsphinx-data
│   │   ├── dictionary.txt
│   │   ├── hmm
│   │   │   ├── feat.params
│   │   │   ├── mdef
│   │   │   ├── means
│   │   │   ├── noisedict
│   │   │   ├── sendump
│   │   │   ├── transition_matrices
│   │   │   └── variances
│   │   └── keywords.txt
│   ├── spectrum_analyzer.py
│   ├── spi.py
│   ├── usb_hid
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-37.pyc
│   │   │   ├── hidapi_backend.cpython-37.pyc
│   │   │   ├── interface.cpython-37.pyc
│   │   │   ├── pyusb_backend.cpython-37.pyc
│   │   │   └── pywinusb_backend.cpython-37.pyc
│   │   ├── hidapi_backend.py
│   │   ├── interface.py
│   │   ├── pyusb_backend.py
│   │   └── pywinusb_backend.py
│   └── vad.py
├── smart_speaker.py
├── src
├── tree.txt
└── voicetext
    ├── __init__.py
    └── __pycache__
        └── __init__.cpython-37.p

Example 1 Wakewordを認識したら効果音を鳴らしたい

Wakewordを認識した後に「ピコッ」とか「ピピッ」ってなった方がスマートスピーカーっぽいですよね。認識した後にユーザーに認識したことを伝える効果音をつけましょう。フリー音源を提供するサイトからwav形式の適当な音源を用意してください。

def wakeword()を作る。

smart_speaker.py
def wakeword():
    #用意した効果音の置いてある場所
    file = "./audio/wakeword.wav"
    playWav(file)

def main()の中に入れる。

smart_speaker.py
def main(): 
    quit_event = Event()
    if task(quit_event) is True:
        wakeword()
        while True:
            mic_input = input_audio()
            WrpSimpleTester.main(mic_input)

もしも、OSError:[Errno -9997] Invalid sample rateのようなエラーが出た場合は、Audacityで音声ファイルを編集してください。その際、Audacityを開いたらProject Rateを44100Hzに設定して保存してください。

Example 2 LEDを光らせたい

実はReSpeakerは、スマートスピーカーの開発ボードとしてマイクだけではなく、LEDも搭載しています。

試しにLEDを光らせてみる場合

cd ~/git
git clone https://github.com/respeaker/4mics_hat.git
cd 4mics_hat/
python pixels_demo.py

smart_speaker.pyで動かしたい場合(先に↑を実行すること。)

cd workshop
mv ~/git/4mics_hat/* .

smart_speaker.pyを以下のように変更する

smart_speaker.py
from pixels import Pixels, pixels 
from google_home_led_pattern import GoogleHomeLedPattern

def main()に以下のコードを追加

smart_speaker.py
def main():
    quit_event = Event()
    if task(quit_event) is True:
        pixels.pattern = GoogleHomeLedPattern(show=pixels.show)
        while True:
            pixels.speak()
            mic_input = input_audio()
            WrpSimpleTester.main(mic_input)

Example 3 Wakeword を変えたい

Wakewordを変えたい人は以下のファイルを変更してください。

nano /home/pi/workshop/respeaker/pocketsphinx-data/keywords.txt

追加したいワード /長さ/ を追加して保存

nano /home/pi/workshop/respeaker/pocketsphinx-data/dictionary.txt

追加したいワード 発音を追加して保存

IPA音声記号などを参考にする
例えば「respeaker」の場合「R IY S P IY K ER」となる。

nano /home/pi/workshop/smart_speaker.py
42行目のif mic.wakeup('respeaker'):if mic.wakeup(追加したいワード):に編集する。

Example 4 賢いスマートスピーカーを作りたい

「賢いスマートスピーカー」を担うのは、今回の構成で言いますとCOTOBA Agentにあたります。シナリオを細く準備することで「賢さ」を実装出来ます。

参考文献

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?