HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2017/11/30

Raspberry Pi 3に Google Cloud Speech APIを入れて各国の言語で音声認識をする方法 Raspberry Pi 3に Google Cloud Speech APIを入れて各国の言語で音声認識をする方法

(ラズパイに Google Cloud Speech APIを設定する方法(Node.js言語編))

Tags: [Raspberry Pi], [電子工作]





● Raspberry Pi 3 Model Bを遂に購入

 Raspberry Pi3 Model B RPI2 RPI3

 大人気の CPUボードの Raspberry Piに WiFiと Bluetoothが搭載されたモデルが新発売となりました。
 以前から Raspberry Pi 2を買おうかどうか迷っていましたが、Raspberry Pi 3 Model Bの発売を機に購入を決意してラズベリアンになる事にしました。

 ※ ラズパイの OS Raspbianはバージョンが上がる毎に過去の版と OSの内部の作りが変わり、過去に書かれた製作記事(例えば Raspbian Wheezyの時代の記事)がそのままではエラーが出たりして動かない事が有ります。
 ※ 当方のホームページのラズパイ記事は全て Raspberry Pi 3 Model Bと Raspbian Jessieの組み合わせで動作確認をしております。
(ただし、将来的に新しい Raspbian OSが出た場合に、当方の Raspbian Jessieを基にした内容がそのままでは動かない可能性が有ります。)
 ※ 2017/08/16から Raspbian OSは Raspbian Jessieから Raspbian Stretchに変わりました。
 ※ 2019/06/20から Raspbian OSは Raspbian Stretchから Raspbian Busterに変わりました。

Download Raspbian for Raspberry Pi

ちなみに、歴代のバージョンと名称は
Debianコードネーム年月備考(参考)Ubuntuでの該当名称
Debian 11Bullseye2021/08/14~2021/11からラズパイにリリースFocal Fossa 20.04 LTS ?
Debian 10Buster2019/06/20~2019/06からラズパイ4対応Bionic 18.04 LTS
Debian 9Stretch2017/08/16~2018/03からラズパイ3B+対応Xenial 16.04 LTS
Debian 8Jessie2015~2016/02からラズパイ3対応Trusty 14.04 LTS
Debian 7Wheezy2013~2016
Debian 6.0Squeeze2011~2014
Debian GNU/Linux 5.0Lenny2009~2012


● Raspberry Pi 3で Cloud Speech API クライアント ライブラリで音声認識

Cloud Speech API クライアント ライブラリ
Google Cloud Speech API Node.js Client

 下記は Node.jsクライアントの古い場所(もう無い)
Samples for the Google Cloud Speech API Node.js Client have moved to github.com/googleapis/nodejs-speech/tree/master/samples/.




$ nodejs -v
v4.8.2

Node.js v8.x

# Node.js v8.x
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

sudo apt-get -y install nodejs

pi@raspberrypi:~/java-docs-samples/speech/cloud-client $ node -v
v8.9.1
pi@raspberrypi:~/java-docs-samples/speech/cloud-client $ nodejs -v
v8.9.1
pi@raspberrypi:~/java-docs-samples/speech/cloud-client $ npm -v
5.5.1





cd
mkdir node
cd node/

npm install --save @google-cloud/speech




サービス アカウント キーの作成
App Engine
JSON

export GOOGLE_APPLICATION_CREDENTIALS='/home/pi/hogehoge-xxxxxxxxxxxx.json'




# Google Cloud Speech API: Node.js Client

Node.js client for Google Cloud Speech: Speech to text conversion powered by machine learning. https://cloud.google.com/speech/

https://github.com/googleapis/nodejs-speech

git clone https://github.com/googleapis/nodejs-speech.git

cd nodejs-speech

# Google Cloud Speech API: Node.js Samples
cd samples
ls -l

pi@raspberrypi:~/node/nodejs-speech/samples $ ls -l
-rw-r--r-- 1 pi pi   654 Dec  3 06:39 package.json
-rw-r--r-- 1 pi pi  1795 Dec  3 06:39 quickstart.js
-rw-r--r-- 1 pi pi  3755 Dec  3 06:39 README.md
-rw-r--r-- 1 pi pi 16780 Dec  3 06:39 recognize.js
drwxr-xr-x 2 pi pi  4096 Dec  3 06:39 resources
drwxr-xr-x 2 pi pi  4096 Dec  3 06:39 system-test

npm install




pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js --help
recognize.js <command>

Commands:
  recognize.js sync <filename>           Detects speech in a local audio file.
  recognize.js sync-gcs <gcsUri>         Detects speech in an audio file located in a Google Cloud Storage bucket.
  recognize.js sync-words <filename>     Detects speech in a local audio file with word time offset.
  recognize.js async <filename>          Creates a job to detect speech in a local audio file, and waits for the job to
                                         complete.
  recognize.js async-gcs <gcsUri>        Creates a job to detect speech in an audio file located in a Google Cloud
                                         Storage bucket, and waits for the job to complete.
  recognize.js async-gcs-words <gcsUri>  Creates a job to detect speech  with word time offset in an audio file located
                                         in a Google Cloud Storage bucket, and waits for the job to complete.
  recognize.js stream <filename>         Detects speech in a local audio file by streaming it to the Speech API.
  recognize.js listen                    Detects speech in a microphone input stream. This command requires that you
                                         have SoX installed and available in your $PATH. See
                                         https://www.npmjs.com/package/node-record-lpcm16#dependencies

Options:
  --version              Show version number                                                                   [boolean]
  --encoding, -e                                                                          [string] [default: "LINEAR16"]
  --sampleRateHertz, -r                                                                        [number] [default: 16000]
  --languageCode, -l                                                                         [string] [default: "en-US"]
  --help                 Show help                                                                             [boolean]

Examples:
  node recognize.js sync ./resources/audio.raw -e LINEAR16 -r 16000
  node recognize.js async-gcs gs://gcs-test-data/vr.flac -e FLAC -r 16000
  node recognize.js stream ./resources/audio.raw  -e LINEAR16 -r 16000
  node recognize.js listen

For more information, see https://cloud.google.com/speech/docs


● Gitのサンプル音声の音声認識

pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js sync ./resources/audio.raw
Transcription:  how old is the Brooklyn Bridge

pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js sync ./resources/audio2.raw
Transcription:  the rain in Spain stays mainly on the plain

pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js sync ./resources/quit.raw
Transcription:  quit
 100%の認識率




$ node recognize.js --version
0.0.1


● FLAC形式の音声を認識

node recognize.js sync ~/recorded.flac -e FLAC -l ja-JP

pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js sync ~/recorded.flac -e FLAC -l ja-JP
Transcription:  こんにちは音声認識


● listenは動かず

node recognize.js listen -l ja-JP

pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js listen -l ja-JP
Listening, press Ctrl+C to stop.
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: spawn rec ENOENT
    at _errnoException (util.js:1024:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:678:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3


●音声認識

女性声優・雛乃木まや公式サイト 〜ナレーションやキャラボイスを依頼できます〜

“留守番電話のアナウンス音声”のフリー女性音声ボイスを無料でお使い頂けます。
 2016.10.05 クレジットフリー・無料音声のダウンロード

wget http://hinanogimaya.com/wp-content/uploads/2016/10/voice-odenwa-arigatougozaimasu-taihenmoushiwake.wav

pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js sync ./voice-odenwa-arigatougozaimasu-taihenmoushiwake.wav -l ja-JP
ERROR: { Error: sample_rate_hertz (16000) in RecognitionConfig must either be omitted or match the value in the WAV header ( 44100).
    at /home/pi/node/nodejs-speech/samples/node_modules/grpc/src/client.js:554:15
  code: 3,
  metadata: Metadata { _internal_repr: {} },
  note: 'Exception occurred in retry method that was not classified as transient' }

pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js sync ./voice-odenwa-arigatougozaimasu-taihenmoushiwake.wav -l ja-JP -r 44100
Transcription:  お電話ありがとうございます大変申し訳ありませんが本日の営業は終了させていただきましたまたおかけ直しいただきますようお願い申し上げます
 100%の認識率


●音声認識

総務省|平成27年版 情報通信白書|PDF版
http://www.soumu.go.jp/johotsusintokei/whitepaper/ja/h27/pdf/index.html

平成27年版情報通信白書 特集テーマ 「ICTの過去・現在・未来」PDF(481KB)
http://www.soumu.go.jp/johotsusintokei/whitepaper/ja/h27/pdf/27dounyu.pdf

本年2015年は1985年の通信自由化から30周年の節目の年であり、ICT産業の発展経緯や産業構造の変遷、これまでの通信政策とその効果などICTの過去への関心が高まっている。
それと同時に、2020年東京オリンピック・パラリンピック競技大会の開催決定を一つの契機として、国民の未来への関心も高まっている。
人口急減・超高齢化への対応や地方創生といった我が国の将来課題に対し、社会全体のICT化を通じてどのように解決を図っていくかに注目が集まっている。新興国市場の急速な拡大を見据えた我が国ICT産業の国際展開戦略も引き続き重要課題である。

 の最初の文章を音声にして認識にさせました。

Sound of Text
voice1.mp3 (24kHz)
 を 16kHzの WAV形式に変換
voice1.wav

Sound of Text
pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js sync ./voice1.wav -l ja-JP
Transcription:  本年2015年は1985年の通信自由化から30周年の節目の年であり ict 産業の発展経緯や産業構造の変遷これまでの通信政策とその効果など ict の過去への関心が高まっている
 100%の認識率

Windows SpeechApp11 Microsoft Speech Platform 11用の Text-to-Speech

2012/04/03
日本語や中国語等の音声合成(TTS)を無料で使う方法
日本語や中国語等の音声合成(TTS)を無料で使う方法

  Microsoft Speech Platform 11 Server Runtimeのインストール方法 多言語対応の Text to Speech

ja-JP Haruka
haruka.wav

ja-JP Haruka
pi@raspberrypi:~/node/nodejs-speech/samples $ node recognize.js sync ./haruka.wav -l ja-JP
Transcription:  本年2015年は1985年の通信自由化から30周年の節目の年であり ict 産業の発展経緯や産業構造の変遷これまでの通信政策とその効果など ict の過去への関心が高まっている
 100%の認識率



Tags: [Raspberry Pi], [電子工作]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

Raspberry Pi 3に USB Micを接続して日本語の音声認識をする方法(Julius編)
Raspberry Pi 3に USB Micを接続して日本語の音声認識をする方法(Julius編)

  ラズパイ3で汎用大語彙連続音声認識エンジン Juliusをコンパイルして使用する方法

Raspberry Pi 3に PyAudioを入れて USBマイクを接続して音声入力を行なう方法
Raspberry Pi 3に PyAudioを入れて USBマイクを接続して音声入力を行なう方法

  ラズパイに USB Micを接続して音声入力をする方法(PyAudio編)

Raspberry Pi 3に PortAudioを入れて USBマイクを接続して音声入力を行なう方法
Raspberry Pi 3に PortAudioを入れて USBマイクを接続して音声入力を行なう方法

  ラズパイに USB Micを接続して音声入力をする方法(PortAudio編)

Raspberry Pi 3に日本語 OCR Tesseractをインストールして OCR文字認識をする方法
Raspberry Pi 3に日本語 OCR Tesseractをインストールして OCR文字認識をする方法

  ラズパイ3で オープンソースの OCRエンジン Tesseractをインストールして使用する方法まとめ

Raspberry Pi 3に日本語 OCR NHocrをビルドして OCR文字認識をする方法
Raspberry Pi 3に日本語 OCR NHocrをビルドして OCR文字認識をする方法

  ラズパイ3で オープンソースの OCRエンジン NHocrをコンパイルして使用する方法まとめ

Raspberry Pi 3で日本語音声を合成して喋らせる方法(AquesTalk編)
Raspberry Pi 3で日本語音声を合成して喋らせる方法(AquesTalk編)

  ラズパイ3で 音声合成アプリ AquesTalk Piを使用してお手軽に日本語文章を喋らせる方法

Raspberry Pi 3で日本語音声を合成して喋らせる方法(OpenJTalk編)
Raspberry Pi 3で日本語音声を合成して喋らせる方法(OpenJTalk編)

  ラズパイ3で 音声合成システム Open JTalkをコンパイルして、お手軽に日本語の文章を喋らせる方法

Raspberry Pi 3で音声合成して喋らせる方法(英語、中国語編)
Raspberry Pi 3で音声合成して喋らせる方法(英語、中国語編)

  ラズパイ3で 音声合成アプリを使用してお手軽に英語と中国語の文章を喋らせる方法

Raspberry Pi 3に形態素解析エンジン MeCabをインストールして形態素解析をする方法
Raspberry Pi 3に形態素解析エンジン MeCabをインストールして形態素解析をする方法

  ラズパイ3で オープンソースの形態素解析エンジン MeCabをコンパイルして使用する方法まとめ

Raspberry Pi 3に Google Cloud Speech APIを入れて各国の言語で音声認識をする方法
Raspberry Pi 3に Google Cloud Speech APIを入れて各国の言語で音声認識をする方法

  ラズパイに Google Cloud Speech APIを設定する方法(Python言語編)

Raspberry Pi 3に Google Cloud Speech APIを入れて各国の言語で音声認識をする方法
Raspberry Pi 3に Google Cloud Speech APIを入れて各国の言語で音声認識をする方法

  ラズパイに Google Cloud Speech APIを設定する方法(Java言語編)

Raspberry Pi 3に AVSを入れて Amazon Echoを作る方法(Alexa Voice Service)
Raspberry Pi 3に AVSを入れて Amazon Echoを作る方法(Alexa Voice Service)

  ラズパイを Amazon Echoにする方法、Alexa Voice Service AVSをインストール

Raspberry Piで docomo Developer APIに挑戦 雑談対話 API編
Raspberry Piで docomo Developer APIに挑戦 雑談対話 API編

  ラズパイ + Javaでドコモの docomo Developer supportの雑談対話 APIを動かす

Raspberry Piで docomo Developer APIに挑戦 音声合成 API編
Raspberry Piで docomo Developer APIに挑戦 音声合成 API編

  ラズパイ + Javaでドコモの docomo Developer supportの音声合成 APIを動かす

Visual Studio 2013の C# .NETで 日本語対応の OCR文字認識アプリを自作する方法
Visual Studio 2013の C# .NETで 日本語対応の OCR文字認識アプリを自作する方法

  オフライン環境で動作可能な 世界各国語対応の OCR文字認識アプリを C# .NETで作成、MS製 OCRライブラリを使用

Visual Studio 2013の C#で日本語対応の手書き文字認識アプリを自作する方法
Visual Studio 2013の C#で日本語対応の手書き文字認識アプリを自作する方法

  オフライン環境で動作する世界各国語対応の手書き文字認識アプリを作成、MS製 手書き認識ライブラリを使用

Windows 10の音声合成エンジンを使用して入力した文字列を喋る & Waveファイル書き出し
Windows 10の音声合成エンジンを使用して入力した文字列を喋る & Waveファイル書き出し

  SpeechApp Windows 10用 Speech 音声合成 Text-to-Speech TTSのアプリ

Windows 10対応 Microsoft Speech使用の音声認識アプリ
Windows 10対応 Microsoft Speech使用の音声認識アプリ

  SpeechRecognizeApp 音声認識エンジンを使用してマイク入力の音声を認識します

Windows 10対応の日本語対応の音声合成エンジン TTSアプリを C# .NETで自作する
Windows 10対応の日本語対応の音声合成エンジン TTSアプリを C# .NETで自作する

  Visual Studio 2013の C# .NETで入力した文字列を喋る音声合成 TTSアプリを作成する 世界各国語に対応




[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2017 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_google_cloud_speech_api_stt_nodejs/