如何在Android中使用Google Speech API异步语音识别

时间:2017-11-19 11:11:44

标签: java android api google-cloud-platform google-speech-api

我想将录制的音频文件转换为文本。我尝试使用异步语音识别来使用Google Speech API。

关于如何继续,我几乎没有问题。

1。我想转换音频文字并且不想实时发送。所以我应该使用Asynchronous recgonition?
Google sample project使用 SpeechGrpc 。是否有必要在android ASychronous语音识别中使用?或者我可以使用 SpeechClient 验证后..如何?

2。 SpeechGrpc (com.google.cloud.speech.v1.SpeechGrpc)我的套餐中没有! (com.google.cloud.speech.v1)。我必须从这里安装吗? grpc.io

3。我使用Google Cloud Platform Console API密钥对Speech API( ManagedChannel 对象)进行身份验证,但我无法理解如何使用它以及使用哪个功能用于异步语音识别。

// Authentication 

try {
                GoogleCredentials creds = GoogleCredentials.fromStream(stream);
                creds = creds.createScoped(SCOPE);
                mChannel = ManagedChannelBuilder.forAddress(HOSTNAME, PORT)
                        .intercept(new ClientAuthInterceptor(creds, Executors.newSingleThreadExecutor()))
                        .build();
            }catch (IOException e){
                Log.e(TAG, "Failed to create channel.", e);
            }

所以我应该在认证后做些什么。在android中是否有任何代码参考或文档用于异步语音识别。

1 个答案:

答案 0 :(得分:0)

是的,您需要使用异步请求。

如果文件超过一分钟,您需要将文件上传到Google云存储。 https://cloud.google.com/speech/quotas " *超过1分钟的音频必须使用uri字段来引用Google云端存储中的音频文件。"

我在示例项目中使用该实现并且它运行良好,我建议将SpeechGrpc与longRunningRecognize一起用于请求。

如果使用SpeechGrpc,您可以使用json凭证文件,方法是阅读文件流,然后使用GoogleCredentials进行身份验证。