2017-06-05 26 views
5

Tôi đang sử dụng Bluemix của IBM để phiên âm một số âm thanh và tôi muốn sử dụng nhận dạng loa của API.Android Bluemix không hiển thị thẻ loa

tôi thiết lập các bộ nhận dạng như thế này:

private RecognizeOptions getRecognizeOptions() { 
    return new RecognizeOptions.Builder() 
      .continuous(true) 
      .contentType(ContentType.OPUS.toString()) 
      //.model("en-US") 
      .model("en-US_BroadbandModel") 
      .timestamps(true) 
      .smartFormatting(true) 
      .interimResults(true) 
      .speakerLabels(true) 
      .build(); 
} 

Nhưng JSON doesnt trở bao gồm thẻ loa. Làm thế nào tôi có thể nhận được thẻ loa cũng quay trở lại với API java bluemix?

máy ghi âm của tôi trong Android trông như thế này:

private void recordMessage() { 
    //mic.setEnabled(false); 
    speechService = new SpeechToText(); 
    speechService.setUsernameAndPassword("usr", "pwd"); 
    if(listening != true) { 
     capture = new MicrophoneInputStream(true); 
     new Thread(new Runnable() { 
      @Override public void run() { 
       try { 
        speechService.recognizeUsingWebSocket(capture, getRecognizeOptions(), new MicrophoneRecognizeDelegate()); 
       } catch (Exception e) { 
        showError(e); 
       } 
      } 
     }).start(); 
     Log.v("TAG",getRecognizeOptions().toString()); 
     listening = true; 
     Toast.makeText(MainActivity.this,"Listening....Click to Stop", Toast.LENGTH_LONG).show(); 
    } else { 
     try { 
      capture.close(); 
      listening = false; 
      Toast.makeText(MainActivity.this,"Stopped Listening....Click to Start", Toast.LENGTH_LONG).show(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 
+0

Tôi nghĩ rằng bạn có nghĩa rằng ông nên thêm thẻ speech-to-text, không phải văn bản thành giọng nói;) –

+0

@bear tệp âm thanh và phương thức nhận dạng bạn đang sử dụng là gì? bạn đang sử dụng WebSockets? –

+0

@GermanAttanasio Tôi đang sử dụng api phát trực tuyến âm thanh của Android, xem đoạn mã được cập nhật của tôi – bear

Trả lời

0

Dựa trên ví dụ của bạn tôi đã viết một ứng dụng mẫu và nhận được các nhãn loa để làm việc.

Đảm bảo bạn đang sử dụng Java-SDK 4.2.1. Trong build.gradle bạn thêm

compile 'com.ibm.watson.developer_cloud:java-sdk:4.2.1' 

Dưới đây là đoạn mã mà công nhận một WAV file từ assets thư mục sử dụng WebSockets, kết quả tạm thời, và nhãn loa.

RecognizeOptions options = new RecognizeOptions.Builder() 
    .contentType("audio/wav") 
    .model(SpeechModel.EN_US_NARROWBANDMODEL.getName()) 
    .interimResults(true) 
    .speakerLabels(true) 
    .build(); 

SpeechToText service = new SpeechToText(); 
service.setUsernameAndPassword("SPEECH-TO-TEXT-USERNAME", "SPEECH-TO-TEXT-PASSWORD"); 

InputStream audio = loadInputStreamFromAssetFile("speaker_label.wav"); 

service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() { 
    @Override 
    public void onTranscription(SpeechResults speechResults) { 
     Assert.assertNotNull(speechResults); 
     System.out.println(speechResults.getResults().get(0).getAlternatives().get(0).getTranscript()); 
     System.out.println(speechResults.getSpeakerLabels()); 
    } 
}); 

đâu loadInputStreamFromAssetFile() là:

public static InputStream loadInputStreamFromAssetFile(String fileName){ 
    AssetManager assetManager = getAssets(); // From Context 
    try { 
    InputStream is = assetManager.open(fileName); 
    return is; 
    } catch (IOException e) { 
    e.printStackTrace(); 
    } 
    return null; 
} 

log Application:

I/System.out: so how are you doing these days 
I/System.out: so how are you doing these days things are going very well glad to hear 
I/System.out: so how are you doing these days things are going very well glad to hear I think I mentioned 
I/System.out: so how are you doing these days things are going very well glad to hear I think I mentioned before that there's a company now that I'm 
I/System.out: so how are you doing these days things are going very well glad to hear I think I mentioned before that there's a company now that I'm working with which is very much 
I/System.out: so how are you doing these days things are going very well glad to hear I think I mentioned before that there's a company now that I'm working with which is very much just just myself and Chris now 
I/System.out: so how are you doing these days things are going very well glad to hear I think I mentioned before that there's a company now that I'm working with which is very much just just myself and Chris now you had mentioned that %HESITATION okay 
I/System.out: so how are you doing these days things are going very well glad to hear I think I mentioned before that there's a company now that I'm working with which is very much just just myself and Chris now you had mentioned that %HESITATION okay 
I/System.out: [{ 
I/System.out: "confidence": 0.487, 
I/System.out: "final": false, 
I/System.out: "from": 0.03, 
I/System.out: "speaker": 0, 
I/System.out: "to": 0.34 
I/System.out: }, { 
I/System.out: "confidence": 0.487, 
I/System.out: "final": false, 
I/System.out: "from": 0.34, 
I/System.out: "speaker": 0, 
I/System.out: "to": 0.54 
I/System.out: }, { 
I/System.out: "confidence": 0.487, 
I/System.out: "final": false, 
I/System.out: "from": 0.54, 
I/System.out: "speaker": 0, 
I/System.out: "to": 0.63 
I/System.out: }, { 
...... blah blah blah 
I/System.out: }, { 
I/System.out: "confidence": 0.343, 
I/System.out: "final": false, 
I/System.out: "from": 13.39, 
I/System.out: "speaker": 1, 
I/System.out: "to": 13.84 
I/System.out: }] 
Các vấn đề liên quan