java - 在java中添加对谷歌云语音的boost适配
问题描述
我正在使用谷歌的云语音 api 通过麦克风进行语音到文本的转换,谁能告诉我如何为我的 java 代码添加增强适应,以便我可以为某些短语分配适当的增强值。我需要在java中做到这一点。我已经阅读了一个谷歌文档,其中显示了如何在 json 请求中添加值:这是该链接:“ https://cloud.google.com/speech-to-text/docs/speech-adaptation ”(在底部)
我需要在java中做同样的事情。
解决方案
您可以setBoost
在SpeechContext
builder 和builderaddSpeechContexts
中使用RecognitionConfig
。
List<String> phrases = new ArrayList<String>();
phrases.add("Sheryar");
SpeechContext item = SpeechContext.newBuilder().addAllPhrases(phrases).setBoost(20f).build();
RecognitionConfig recognitionConfig = RecognitionConfig.newBuilder().setEncoding(RecognitionConfig.AudioEncoding.LINEAR16).setLanguageCode("en-IN").addSpeechContexts(item).setSampleRateHertz(48000).setEnableWordTimeOffsets(true);
您需要执行以下导入:
import com.google.cloud.speech.v1p1beta1.RecognitionAudio;
import com.google.cloud.speech.v1p1beta1.RecognitionConfig;
import com.google.cloud.speech.v1p1beta1.RecognizeRequest;
import com.google.cloud.speech.v1p1beta1.RecognizeResponse;
import com.google.cloud.speech.v1p1beta1.SpeechClient;
import com.google.cloud.speech.v1p1beta1.SpeechContext;
import com.google.cloud.speech.v1p1beta1.SpeechRecognitionAlternative;
import com.google.cloud.speech.v1p1beta1.SpeechRecognitionResult;
您需要将以下依赖项添加到您的 pom 中:
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-speech -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-speech</artifactId>
<version>1.22.2</version>
</dependency>
推荐阅读
- git - 为什么我最终会得到一堆合并提交?
- java - 在猜数游戏中用 FOR 循环实现/替换 WHILE 循环
- python - 如何处理时间间隔的求和和乘法?
- pandas - Pandas 以批量大小随机排列顺序数据
- python - 如何为 pcolormesh 指定轴?
- docker - 用于源 bash 配置文件的 Docker RUN 指令
- r - 如何转换具有内存大小的列 Ex。MB & KB,我想要 MB 中的所有值?
- android - 转到链接后的 WebView 空白页
- c# - 如何在单个代理类中添加多个服务引用
- spring - 我想通过使用 cron 表达式设置每 24 小时安排一次任务