I have implemented Google Cloud Speech API in ac# console API.(我已经在ac#控制台API中实现了Google Cloud Speech API。)
Now I want to implement the same on a HTML page.(现在,我想在HTML页面上实现相同的功能。) Below are the steps I have followed:(以下是我遵循的步骤:)
Captured the voice on HTML page using Media recorder and post the same to a WEB API:(使用媒体记录器捕获HTML页面上的声音并将其发布到WEB API:)
mediaRecorder.ondataavailable = function (e) {
chunks.push(e.data);
var blob = new Blob(chunks, { 'type': 'audio/wav; codecs=0' });
var fd = new FormData();
fd.append('fname', 'test.wav');
//fd.append('data', chunks[0]);
fd.append('data', blob);
$.ajax({
type: 'POST',
url: APIUrl,
data: fd,
processData: false,
contentType: false
}).done(function (data) {
console.log(data);
});
On the WEB API I am using Google Cloud speech recognition.(在WEB API上,我正在使用Google Cloud语音识别。) But to my luck, It returns null response.(但令我幸运的是,它返回空响应。) The test file provided by google Audio.raw is working fine with the same code.(google Audio.raw提供的测试文件可以在相同的代码下正常工作。) But any audio sent from webpage is not providing any results.(但是从网页发送的任何音频都无法提供任何结果。)
string text = "";
var speech = SpeechClient.Create();
var response = speech.Recognize(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.OggOpus,
SampleRateHertz = 48000,
LanguageCode = "en",
}, RecognitionAudio.FromStream(HttpContext.Current.Request.Files[0].InputStream));
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
text = alternative.Transcript;
}
}
I have tried different combinations of Encoding and Hertz.(我尝试了编码和赫兹的不同组合。) But none works.(但是没有办法。) Also I tried saving the audio first on local drive in WAV format and reading the response from local file.(我也尝试过先将音频以WAV格式保存在本地驱动器上,然后从本地文件读取响应。) But it does not work either.(但这也不起作用。)
ask by Abhishek translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…