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を設定する方法(Java言語編))

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で

 Javaだと動かなかった。
Exception in thread "main" java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured.

java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured. #2240
garrettjonesgoogle commented Aug 7, 2017
I am going to add a special comment about Raspberry in the README (since this has been asked more than once), then I'll close out this issue. Sorry that we can't be of more help in the near future!

Google Cloud Client Library for Java - Supported Platforms
Supported Platforms
Thus, the following are not supported:

Android
Alpine Linux (due to netty-tcnative requiring glibc, which is not present on Alpine)
Raspberry Pi (since it runs on the ARM architecture)
Google App Engine Standard Java 7
 汎用性の無い使えねえライブラリ作るなよ。ボケ。

pi@raspberrypi:~ $ sudo apt-get -y install google-cloud-sdk-app-engine-java

dpkg: error processing package openjdk-8-jre:armhf (--configure):
 dependency problems - leaving unconfigured
Processing triggers for ca-certificates (20161130+nmu1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

Error: missing `server' JVM at `/usr/lib/jvm/java-8-openjdk-armhf/jre/lib/arm/se rver/libjvm.so'.
Please install or use the JRE or JDK that contains these missing components.
E: /etc/ca-certificates/update.d/jks-keystore exited with code 1.
done.
Errors were encountered while processing:
 ca-certificates-java
 openjdk-8-jre-headless:armhf
 openjdk-8-jdk-headless:armhf
 openjdk-8-jdk:armhf
 google-cloud-sdk-app-engine-java
 openjdk-8-jre:armhf
E: Sub-process /usr/bin/dpkg returned an error code (1)
sudo apt-get -y purge openjdk-8-jre-headless
sudo apt-get -y install openjdk-8-jre-headless
sudo apt-get -y install openjdk-8-jre

sudo apt-get -y install google-cloud-sdk-app-engine-java
pi@raspberrypi:~ $ javac QuickstartSample.java
QuickstartSample.java:2: error: package com.google.cloud.speech.spi.v1beta1 does not exist
import com.google.cloud.speech.spi.v1beta1.SpeechClient;
                                          ^
QuickstartSample.java:3: error: package com.google.cloud.speech.v1beta1 does not exist
import com.google.cloud.speech.v1beta1.RecognitionAudio;
                                      ^
QuickstartSample.java:4: error: package com.google.cloud.speech.v1beta1 does not exist
import com.google.cloud.speech.v1beta1.RecognitionConfig;
                                      ^
QuickstartSample.java:5: error: package com.google.cloud.speech.v1beta1.RecognitionConfig does not exist
import com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding;
                                                        ^
QuickstartSample.java:6: error: package com.google.cloud.speech.v1beta1 does not exist
sudo apt-get -y install maven

pi@raspberrypi:~ $ java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-1~deb9u1-b12)
OpenJDK Client VM (build 25.151-b12, mixed mode)
pi@raspberrypi:~ $ javac -version
javac 1.8.0_151
pi@raspberrypi:~ $ mvn -version
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-armhf/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.9.41-v7+", arch: "arm", family: "unix"


cd
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
cd java-docs-samples/
mvn compile
mvn assembly:single

# Quickstart
cd speech/cloud-client/
mvn clean compile assembly:single
pi@raspberrypi:~/java-docs-samples/speech/cloud-client $ java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
>   com.example.speech.Recognize syncrecognize ./resources/audio.raw

Exception in thread "main" java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
        at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:119)
        at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:127)
        at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:100)
        at com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:53)
        at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:110)
        at com.google.cloud.speech.v1.stub.GrpcSpeechStub.create(GrpcSpeechStub.java:93)
        at com.google.cloud.speech.v1.SpeechSettings.createStub(SpeechSettings.java:128)
        at com.google.cloud.speech.v1.SpeechClient.<init>(SpeechClient.java:143)
        at com.google.cloud.speech.v1.SpeechClient.create(SpeechClient.java:125)
        at com.google.cloud.speech.v1.SpeechClient.create(SpeechClient.java:117)
        at com.example.speech.Recognize.syncRecognizeFile(Recognize.java:91)
        at com.example.speech.Recognize.main(Recognize.java:65)
export GOOGLE_APPLICATION_CREDENTIALS='/home/pi/hogehoge-xxxxxxxxxxxx.json'
java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
  com.example.speech.Recognize syncrecognize ./resources/audio.raw


Exception in thread "main" java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured.
        at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:162)

Caused by: java.lang.ClassNotFoundException: org/eclipse/jetty/alpn/ALPN
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at io.grpc.netty.JettyTlsUtil.isJettyAlpnConfigured(JettyTlsUtil.java:34)
        at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:153)
        ... 18 more

cd
https://github.com/GoogleCloudPlatform/java-docs-samples/tree/tasks/speech/grpc

git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git -b tasks

cd java-docs-samples/

cd speech/grpc/
mvn clean compile assembly:single

./bin/speech-sample-streaming.sh --host=speech.googleapis.com --port=443 --sampling=16000


pi@raspberrypi:~/ta/java-docs-samples/speech/grpc $ ./bin/speech-sample-streaming.sh --host=speech.googleapis.com --port=443 --sampling=16000
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Dec 03, 2017 5:46:41 AM io.grpc.internal.ManagedChannelImpl <init>
INFO: [ManagedChannelImpl@159c4b8] Created with target speech.googleapis.com:443
Exception in thread "grpc-default-executor-1" java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured.
        at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:153)
        at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:130)
        at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:119)
        at io.grpc.netty.GrpcSslContexts.forClient(GrpcSslContexts.java:90)
        at io.grpc.netty.NettyChannelBuilder.createProtocolNegotiator(NettyChannelBuilder.java:265)
        at io.grpc.netty.NettyChannelBuilder$NettyTransportFactory.newClientTransport(NettyChannelBuilder.java:324)
        at io.grpc.internal.CallCredentialsApplyingTransportFactory.newClientTransport(CallCredentialsApplyingTransportFactory.java:62)
        at io.grpc.internal.TransportSet.startNewTransport(TransportSet.java:215)
        at io.grpc.internal.TransportSet.obtainActiveTransport(TransportSet.java:192)
        at io.grpc.internal.ManagedChannelImpl$3.getTransport(ManagedChannelImpl.java:651)
        at io.grpc.internal.ManagedChannelImpl$3.getTransport(ManagedChannelImpl.java:592)
        at io.grpc.DummyLoadBalancerFactory$DummyLoadBalancer$1.get(DummyLoadBalancerFactory.java:135)
        at io.grpc.internal.DelayedClientTransport$2.run(DelayedClientTransport.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
ERROR - recognize failed: {0}
io.grpc.StatusRuntimeException: CANCELLED: Cancelled by client with StreamObserver.onError()
        at io.grpc.Status.asRuntimeException(Status.java:545)
        at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:395)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:481)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:398)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:513)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
        at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: javax.sound.sampled.LineUnavailableException
        at com.examples.cloud.speech.StreamingRecognizeClient.getAudioInputLine(StreamingRecognizeClient.java:135)
        at com.examples.cloud.speech.StreamingRecognizeClient.recognize(StreamingRecognizeClient.java:213)
        at com.examples.cloud.speech.StreamingRecognizeClient.main(StreamingRecognizeClient.java:290)
Caused by: javax.sound.sampled.LineUnavailableException
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openImpl(PulseAudioMixer.java:714)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:588)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:584)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.open(PulseAudioMixer.java:579)
        at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:94)
        at org.classpath.icedtea.pulseaudio.PulseAudioTargetDataLine.open(PulseAudioTargetDataLine.java:111)
        at com.examples.cloud.speech.StreamingRecognizeClient.getAudioInputLine(StreamingRecognizeClient.java:132)
        ... 2 more
Dec 03, 2017 5:46:44 AM io.grpc.internal.ManagedChannelImpl maybeTerminateChannel
INFO: [ManagedChannelImpl@159c4b8] Terminated
Exception in thread "main" java.lang.RuntimeException: javax.sound.sampled.LineUnavailableException
        at com.examples.cloud.speech.StreamingRecognizeClient.getAudioInputLine(StreamingRecognizeClient.java:135)
        at com.examples.cloud.speech.StreamingRecognizeClient.recognize(StreamingRecognizeClient.java:213)
        at com.examples.cloud.speech.StreamingRecognizeClient.main(StreamingRecognizeClient.java:290)
Caused by: javax.sound.sampled.LineUnavailableException
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openImpl(PulseAudioMixer.java:714)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:588)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:584)
        at org.classpath.icedtea.pulseaudio.PulseAudioMixer.open(PulseAudioMixer.java:579)
        at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:94)
        at org.classpath.icedtea.pulseaudio.PulseAudioTargetDataLine.open(PulseAudioTargetDataLine.java:111)
        at com.examples.cloud.speech.StreamingRecognizeClient.getAudioInputLine(StreamingRecognizeClient.java:132)
        ... 2 more

----------------------
jetty-alpn-agent-2.0.6.jar
Jetty ALPN/NPN Agent - 2.0.6
https://mvnrepository.com/artifact/org.mortbay.jetty.alpn/jetty-alpn-agent/2.0.6

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>

<!-- https://mvnrepository.com/artifact/org.mortbay.jetty.alpn/jetty-alpn-agent -->
<dependency>
    <groupId>org.mortbay.jetty.alpn</groupId>
    <artifactId>jetty-alpn-agent</artifactId>
    <version>2.0.6</version>
</dependency>

  </dependencies>
  <!-- // [END dependency] -->


-------------


java-docs-samples/speech/cloud-client
mvn clean compile assembly:single
nano pom.xml

  <dependencies>
    <!-- [START dependencies] -->
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-speech</artifactId>
      <version>0.30.0-alpha</version>
    </dependency>

<!-- https://mvnrepository.com/artifact/org.mortbay.jetty.alpn/jetty-alpn-agent $
<dependency>
    <groupId>org.mortbay.jetty.alpn</groupId>
    <artifactId>jetty-alpn-agent</artifactId>
    <version>2.0.6</version>
</dependency>


    <!-- [END dependencies] -->


java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
  com.example.speech.Recognize syncrecognize ./resources/audio.raw


https://github.com/GoogleCloudPlatform/java-docs-samples/issues/766
Speech Api - Jetty ALPN/NPN has not been properly configured. #766
opened this issue Jul 24, 2017 · 18 comments

https://github.com/GoogleCloudPlatform/google-cloud-java/issues/2483
Error: Jetty ALPN/NPN has not been properly configured. #2483
opened this issue Oct 5, 2017 · 13 comments

https://github.com/grpc/grpc-java/issues/3025
Stop telling people Jetty ALPN has not been configured #3025
opened this issue May 19, 2017 · 12 comments


--------
Netty/TomcatNative [BoringSSL Static] » 2.0.7.Final
https://mvnrepository.com/artifact/io.netty/netty-tcnative-boringssl-static/2.0.7.Final

nano pom.xml

<!-- https://mvnrepository.com/artifact/io.netty/netty-tcnative-boringssl-static -->
<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-tcnative-boringssl-static</artifactId>
    <version>2.0.7.Final</version>
</dependency>



mvn clean compile assembly:single

java -cp target/speech-google-cloud-samples-1.0.0-jar-with-dependencies.jar \
  com.example.speech.Recognize syncrecognize ./resources/audio.raw



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を設定する方法(Node.js言語編)

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_java/