我想在其中使用Google Cloud Speech API和Android应用程序,并且我正在跟踪google https://cloud.google.com/speech-to-text/docs/libraries#client-libraries-install-java提供的此链接>
我已经尝试了链接https://developers.google.com/accounts/docs/application-default-credentials中提供的解决方案,但仍然无法正常工作。
Windows环境变量用户和系统都具有GOOGLE_APPLICATION_CREDENTIALS = C:\ Users \ ANSH \ Downloads \ credential.json
存在所有必需的导入。
private void recognizeSpeech(){ try{ SpeechClient speechClient = SpeechClient.create(); String languageCode="en-US"; int sampleRateHertz=16000; RecognitionConfig.AudioEncoding encoding = RecognitionConfig.AudioEncoding.LINEAR16; RecognitionConfig config = RecognitionConfig.newBuilder() .setLanguageCode(languageCode) .setSampleRateHertz(sampleRateHertz) .setEncoding(encoding) .build(); Path path = Paths.get(fileName); byte[] data = Files.readAllBytes(path); ByteString content = ByteString.copyFrom(data); RecognitionAudio audio = RecognitionAudio.newBuilder().setContent(content).build(); RecognizeRequest request = RecognizeRequest.newBuilder().setConfig(config).setAudio(audio).build(); RecognizeResponse response = speechClient.recognize(request); for (SpeechRecognitionResult result : response.getResultsList()) { // First alternative is the most probable result SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); outputText.setText(alternative.getTranscript()); } } catch (Exception e){ Toast.makeText(this, e.toString(), Toast.LENGTH_SHORT).show(); } }
credential.json包含使用服务帐户下载的密钥
[https://cloud.google.com/speech-to-text/docs/libraries提到一个音符。
注意:Cloud Java客户端库当前不支持Android。
这是否意味着它不能在android studio中使用?如果是,如何使用?
我想在其中使用google cloud cloud语音api和android应用程序,而我正在跟踪google https://cloud.google.com/speech-to-text/docs/libraries#client-libraries-install- java I ...
[您可能想检查此github link以查看异常的解决方式,但是请注意,语音转文本客户端库指定不支持Android,因为它已在注释中发布。