我正在使用节点js客户端编写。我在这里找到了这个项目,https://github.com/googleapis/nodejs-speech并试用了其中的样本。一切正常,但我找不到alternativeLanguageCodes的样本。我发现在版本V1P1Beta1中支持它,如这里所提到的:https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig,如果我们使用alternativeLanguageCodes,api将尝试将音频转录到最相关的语言。我观察到的是,它总是转录成languageCode中指定的语言。
有人有机会尝试这个API吗?如果是这样的话,您能解释一下如何检测到alternativeLanguage吗?
发布于 2018-08-14 14:53:42
使用下面的代码对我是有效的,尽管它确实没有检测到正确的语言。考虑到这个特性还在贝塔。无论如何,请查看它所述的在官方文件中,即:
..。特征很理想..。转录简短的陈述,如语音命令或搜索。
在我的代码中使用这个特定的音频(用英语说“布鲁克林桥有多老”),多次运行它,有时会返回正确的转录,有时还会返回“bre kod braća”。这种行为可能会因所提供的语言、音频示例而有所不同.
const speech = require('@google-cloud/speech').v1p1beta1;
var client = new speech.SpeechClient();
var languageCode = 'sr-SR';
var alternativeLanguageCodes = [`es-ES`,`en-US`];
var model = 'command_and_search';
const config = {
alternativeLanguageCodes:alternativeLanguageCodes,
model:model,
languageCode: languageCode,
};
var uri = 'gs://cloud-samples-tests/speech/brooklyn.flac';
const audio = {
uri: uri,
};
const request = {
config: config,
audio: audio,
};
client.recognize(request).then(data => {const response = data[0]; const transcription = response.results.map(result => result.alternatives[0].transcript).join('\n');console.log(`Transcription: `, transcription); }).catch(err => {console.error('Error:',err);});
https://stackoverflow.com/questions/51622397
复制相似问题