php - Speech to Text using getUserMedia to record audio and Google Cloud Speech for transcribing -
i working on web application(whose back-end in php) requires me record audio browser , send google cloud speech transcribing. having read documentation on google cloud speech, understand audio file (flac or wav) can transcribed using synchronous recognition request.
so far, able record audio using getusermedia audio blob, send on php post parameter, , have php write audio blob .wav file on server. intend make ajax call audio file path parameter google cloud speech transcribing file.
however have noticed .wav file plays on browser, fails play on media player. since have .wav file generated, tried transcribing file using command line:
php speech.php transcribe <path wav file> --encoding flac --sample-rate 32000
as given in readme.md of php client library google cloud speech api, following error:
php notice: undefined offset: 0 in /var/www/html/gcs-poc/speech/src/transcribe_sync.php on line 57 php fatal error: call member function alternatives() on non-object in /var/www/html/gcs-poc/speech/src/transcribe_sync.php on line 57
i suspect encoding , sampling rate parameters input me incorrect. can please guide me in regards this.
the javascript pushes blob post paramter php file:
`
blob = new blob(chunks, { type: 'audio/wav' }); var filetype = 'audio'; // or "audio" var filename = 'abcdef.wav'; // or "wav" var formdata = new formdata(); formdata.append(filetype + '-filename', filename); formdata.append(filetype + '-blob', blob); xhr('savefile.php', formdata, function (fileurl) { window.open(fileurl); }); function xhr(url, data, callback) { var request = new xmlhttprequest(); request.onreadystatechange = function () { if (request.readystate == 4 && request.status == 200) { callback(location.href + request.responsetext); } }; request.open('post', url); request.send(data);`
the php file writes .wav file (i understand loop here unnecessary, since there single file. intend remove later):
foreach(array('video', 'audio') $type) { if (isset($_files["${type}-blob"])) { $filename = $_post["${type}-filename"]; $uploaddirectory = "uploads/$filename"; if (!move_uploaded_file($_files["${type}-blob"]["tmp_name"], $uploaddirectory)) { echo("problem moving uploaded file"); } echo($uploaddirectory); } }
Comments
Post a Comment