Google Speech API不会在Android App中转录.flac音频文件

时间:2018-11-24 17:28:39

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

private void processSpeech( String data ) throws IOException
{
    Speech speechService = new Speech
        .Builder( AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
        .setSpeechRequestInitializer( new SpeechRequestInitializer( CLOUD_API_KEY ) )
        .build();

    RecognitionConfig recognitionConfig = new RecognitionConfig();
    recognitionConfig.setLanguageCode( "en-US" );

    RecognitionAudio recognitionAudio = new RecognitionAudio();
    recognitionAudio.setContent( data );

    SyncRecognizeRequest request = new SyncRecognizeRequest();
    request.setConfig( recognitionConfig );
    request.setAudio( recognitionAudio );

    SyncRecognizeResponse response = speechService.speech()
            .syncrecognize( request ).execute();

    TextView speechToTextResult = ( TextView ) findViewById( R.id.speech_to_text_result );
    speechToTextResult.setText( "Hello" );

    SpeechRecognitionResult result = response.getResults().get( 0 );

    final String transcript = result.getAlternatives().get( 0 ).getTranscript();

    runOnUiThread( new Runnable()
    {
        @Override
        public void run()
        {
            TextView speechToTextResult = ( TextView ) findViewById( R.id.speech_to_text_result );
            speechToTextResult.setText( "Heyyy" );
        }
    } );

}

我使用了this GitHub page中提到的Google Speech API代码。

该应用程序未显示任何编译时错误,但是当我运行它并选择一个.FLAC文件进行转录时-没有任何反应。在将打印语句放入代码后,我似乎已经缩小了以下行中的错误:-

SyncRecognizeResponse response = speechService.speech().syncrecognize(request).execute();

我没有看到任何错误,因此无法调试。除"Couldn't load memtrack module"外,Logcat的显示也不多。关于出什么问题有什么建议吗?

0 个答案:

没有答案