Google Cloud Speech API add SpeechContext(Google Cloud Speech API添加SpeechContext)
本文介绍了Google Cloud Speech API添加SpeechContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的应用程序中添加一些关键字,这样API就可以更高效地识别口语。
例如Im having trouble recognizing the some Italian words that starts with E
、(E`Per Me)等。或德语(呃)。
以下是我的代码:
public void recognize (int sampleRate) {
if (mApi == null) {
Log.w(TAG, "API not ready. Ignoring the request.");
return;
}
// Configure the API
mRequestObserver = mApi.streamingRecognize(mResponseObserver);
mRequestObserver.onNext(StreamingRecognizeRequest.newBuilder()
.setStreamingConfig(StreamingRecognitionConfig.newBuilder()
.setConfig(RecognitionConfig.newBuilder()
.setLanguageCode(getDefaultLanguageCode())
.setEncoding(RecognitionConfig.AudioEncoding.LINEAR16)
.setSampleRateHertz(sampleRate)
.build())
.setInterimResults(true)
.setSingleUtterance(true)
.build())
.build());
}
设置不同大小写的语言:
private String getDefaultLanguageCode() {
SharedPreferences getLangSharedPrefs = getSharedPreferences("langSelected",0);
String selectedLanguage = getLangSharedPrefs.getString("langSelected", null);
switch (selectedLanguage) {
case "German":
langaugeCode = "de-DE";
break;
case "Italian":
langaugeCode = "it-IT";
break;
case "Spanish" :
langaugeCode = "es-ES";
break;
case "French" :
langaugeCode = "fr-FR";
break;
}
return langaugeCode;
}
推荐答案
我找到解决方案了:
public void startRecognizing(int sampleRate) {
if (mApi == null) {
Log.w(TAG, "API not ready. Ignoring the request.");
return;
}
// Configure the API
mRequestObserver = mApi.streamingRecognize(mResponseObserver);
SpeechContext.Builder speechBuilder = SpeechContext.newBuilder();
speechBuilder.addPhrases("E per me");
speechBuilder.addPhrases("E");
mRequestObserver.onNext(StreamingRecognizeRequest.newBuilder()
.setStreamingConfig(StreamingRecognitionConfig.newBuilder()
.setConfig(RecognitionConfig.newBuilder()
.setLanguageCode(getDefaultLanguageCode())
.setEncoding(RecognitionConfig.AudioEncoding.LINEAR16)
.setSampleRateHertz(sampleRate)
.addSpeechContexts(speechBuilder)
.build())
.setInterimResults(true)
.setSingleUtterance(true)
.build())
.build());
}
这篇关于Google Cloud Speech API添加SpeechContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Google Cloud Speech API添加SpeechContext
基础教程推荐
猜你喜欢
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01