質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Google App Engine

Google App Engineは、Googleの管理するデータセンター上でウェブアプリケーションの開発が可能なクラウドコンピュータ技術です。Java、Python、Go用にSDKが用意されています。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

3693閲覧

“400 RecognitionAudio not set” と “InactiveRpcError”のエラーを解決したいです。 [Google text to speech API]

kzkszk

総合スコア6

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Google App Engine

Google App Engineは、Googleの管理するデータセンター上でウェブアプリケーションの開発が可能なクラウドコンピュータ技術です。Java、Python、Go用にSDKが用意されています。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/01/31 23:50

前提・実現したいこと

  1. ブラウザ(Google Chrome)上で音声を録音し、WAVファイルで保存する。(Recorder.js)
  2. WAVファイルをサーバーに送る。(Flask + Google App Engine Standard environment Python 3.7)
  3. Google Cloud text to speech APIを用いてWAVファイルを活字化してブラウザに送る。

という機能を実装中に以下のエラーメッセージが発生しました。

発生している問題・エラーメッセージ

問題は2つあるようです。一つ目の問題。(エラーメッセージ部分)

2020-01-30 08:37:56 speech[20200130t173543] Traceback (most recent call last): File "/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable return callable_(*args, **kwargs) File "/env/lib/python3.7/site-packages/grpc/_channel.py", line 824, in __call__ return _end_unary_response_blocking(state, call, False, None) File "/env/lib/python3.7/site-packages/grpc/_channel.py", line 726, in _end_unary_response_blocking raise _InactiveRpcError(state) grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:

"InactiveRpcError google cloud speech api"で検索しましたが、有用な情報はみつかりませんでした。

二つ目の問題。(エラーメッセージ部分)

2020-01-30 08:37:57 speech[20200130t173543] Traceback (most recent call last): File "/env/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app response = self.full_dispatch_request() File "/env/lib/python3.7/site-packages/flask/app.py", line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File "/env/lib/python3.7/site-packages/flask/app.py", line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File "/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise raise value File "/env/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request rv = self.dispatch_request() File "/env/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/srv/main.py", line 38, in index response = client.recognize(config, audio) File "/env/lib/python3.7/site-packages/google/cloud/speech_v1/gapic/speech_client.py", line 256, in recognize request, retry=retry, timeout=timeout, metadata=metadata File "/env/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__ return wrapped_func(*args, **kwargs) File "/env/lib/python3.7/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func on_error=on_error, File "/env/lib/python3.7/site-packages/google/api_core/retry.py", line 184, in retry_target return target() File "/env/lib/python3.7/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout return func(*args, **kwargs) File "/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable six.raise_from(exceptions.from_grpc_error(exc), exc) File "<string>", line 3, in raise_from google.api_core.exceptions.InvalidArgument: 400 RecognitionAudio not set.

"InvalidArgument: 400 RecognitionAudio not set"で検索したところ、「sample_rate_hertz=16000」を変えたほうが良いというアドバイスがあったので、「48000」にしたり、「sample_rate_hertz」という項目自体を消去したりしましたが、同じエラーメッセージが出ました。

該当のソースコード

何が問題なのか見当がつかないため、GoogleAppEngineにアップロードしているファイルをすべて載せました。2つのエラーメッセージの片方だけでも、また、手掛かりだけでもいただけたら幸いです。よろしくお願いいたします。

AppEngine

1. 2├── app.yaml 3├── credentials.json 4├── main.py 5├── requirements.txt 6├── static 7│ └── js 8│ └── app.js 9└── templates 10 └── index.html

python

1#main.py 2#!/usr/bin/env python 3# -*- coding: utf-8 -*- 4from flask import Flask 5from flask import request 6from flask import render_template 7from flask import send_file 8from google.cloud import speech 9from google.cloud.speech import enums 10from google.cloud.speech import types 11import os 12import io 13 14app = Flask(__name__) 15 16@app.route("/", methods=['POST', 'GET']) 17def index(): 18 if request.method == "POST": 19 f = open('/tmp/file.wav', 'wb') 20 f.write(request.data) 21 f.close() 22 if os.path.isfile('/tmp/file.wav'): 23 print("/tmp/file.wav exists") 24 os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="credentials.json" 25 client = speech.SpeechClient() 26 # [START speech_python_migration_sync_request] 27 # [START speech_python_migration_config] 28 with io.open('/tmp/file.wav', 'rb') as audio_file: 29 content = audio_file.read() 30 31 audio = types.RecognitionAudio(content=content) 32 config = types.RecognitionConfig( 33 encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, 34 sample_rate_hertz=16000, 35 language_code='ja-JP') 36 # [END speech_python_migration_config] 37 38 # [START speech_python_migration_sync_response] 39 response = client.recognize(config, audio) 40 # [END speech_python_migration_sync_request] 41 # Each result is for a consecutive portion of the audio. Iterate through 42 # them to get the transcripts for the entire audio file. 43 for result in response.results: 44 # The first alternative is the most likely one for this portion. 45 print(u'Transcript: {}'.format(result.alternatives[0].transcript)) 46 return print(u'Transcript: {}'.format(result.alternatives[0].transcript)) 47 else: 48 return render_template("index.html") 49 50if __name__ == "__main__": 51 app.run()

html

1//index.html 2<!DOCTYPE html> 3<html> 4 <head> 5 <meta charset="UTF-8"> 6 <title>Simple Recorder.js demo with record, stop and pause - addpipe.com</title> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 </head> 9 <body> 10 <h1>Simple Recorder.js demo</h1> 11 12 <div id="controls"> 13 <button id="recordButton">Record</button> 14 <button id="pauseButton" disabled>Pause</button> 15 <button id="stopButton" disabled>Stop</button> 16 </div> 17 <div id="formats">Format: start recording to see sample rate</div> 18 <p><strong>Recordings:</strong></p> 19 <ol id="recordingsList"></ol> 20 <!-- inserting these scripts at the end to be able to use all the elements in the DOM --> 21 <script src="https://cdn.rawgit.com/mattdiamond/Recorderjs/08e7abd9/dist/recorder.js"></script> 22 <script src="/static/js/app.js"></script> 23 </body> 24</html>

javascript

1//app.js 2//webkitURL is deprecated but nevertheless 3URL = window.URL || window.webkitURL; 4 5var gumStream; //stream from getUserMedia() 6var rec; //Recorder.js object 7var input; //MediaStreamAudioSourceNode we'll be recording 8 9var AudioContext = window.AudioContext || window.webkitAudioContext; 10var audioContext //audio context to help us record 11 12var recordButton = document.getElementById("recordButton"); 13var stopButton = document.getElementById("stopButton"); 14var pauseButton = document.getElementById("pauseButton"); 15 16recordButton.addEventListener("click", startRecording); 17stopButton.addEventListener("click", stopRecording); 18pauseButton.addEventListener("click", pauseRecording); 19 20function startRecording() { 21 console.log("recordButton clicked"); 22 23 var constraints = { audio: true, video:false } 24 25 recordButton.disabled = true; 26 stopButton.disabled = false; 27 pauseButton.disabled = false 28 29 navigator.mediaDevices.getUserMedia(constraints).then(function(stream) { 30 console.log("getUserMedia() success, stream created, initializing Recorder.js ..."); 31 32 audioContext = new AudioContext(); 33 34 document.getElementById("formats").innerHTML="Format: 1 channel pcm @ "+audioContext.sampleRate/1000+"kHz" 35 36 gumStream = stream; 37 38 input = audioContext.createMediaStreamSource(stream); 39 40 rec = new Recorder(input,{numChannels:1}) 41 42 rec.record() 43 44 console.log("Recording started"); 45 46 }).catch(function(err) { 47 recordButton.disabled = false; 48 stopButton.disabled = true; 49 pauseButton.disabled = true 50 }); 51} 52 53function pauseRecording(){ 54 console.log("pauseButton clicked rec.recording=",rec.recording ); 55 if (rec.recording){ 56 //pause 57 rec.stop(); 58 pauseButton.innerHTML="Resume"; 59 }else{ 60 //resume 61 rec.record() 62 pauseButton.innerHTML="Pause"; 63 64 } 65} 66 67function stopRecording() { 68 console.log("stopButton clicked"); 69 70 stopButton.disabled = true; 71 recordButton.disabled = false; 72 pauseButton.disabled = true; 73 74 pauseButton.innerHTML="Pause"; 75 76 rec.stop(); 77 78 gumStream.getAudioTracks()[0].stop(); 79 80 rec.exportWAV(createDownloadLink); 81} 82 83function createDownloadLink(blob) { 84 85 var url = URL.createObjectURL(blob); 86 var au = document.createElement('audio'); 87 var li = document.createElement('li'); 88 var link = document.createElement('a'); 89 90 var filename = new Date().toISOString(); 91 92 au.controls = true; 93 au.src = url; 94 95 link.href = url; 96 link.download = filename+".wav"; 97 link.innerHTML = "Save to disk"; 98 99 li.appendChild(au); 100 101 li.appendChild(document.createTextNode(filename+".wav ")) 102 103 li.appendChild(link); 104 105 var upload = document.createElement('a'); 106 upload.href="#"; 107 upload.innerHTML = "Upload"; 108 upload.addEventListener("click", function(event){ 109 var xhr=new XMLHttpRequest(); 110 xhr.onload=function(e) { 111 if(this.readyState === 4) { 112 console.log("Server returned: ",e.target.responseText); 113 } 114 }; 115 var fd=new FormData(); 116 fd.append("audio_data",blob, filename); 117 xhr.open("POST","/",true); 118 xhr.send(fd); 119 }) 120 li.appendChild(document.createTextNode (" "))//add a space in between 121 li.appendChild(upload)//add the upload link to li 122 123 recordingsList.appendChild(li); 124}

補足情報

Windows 10, WSL, Debian 10/buster を使っています。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問