【问题标题】:Android Bluemix not showing speaker tagAndroid Bluemix 未显示扬声器标签
【发布时间】:2017-11-05 19:24:18
【问题描述】:

我正在使用 IBM bluemix 转录一些音频,并且我想使用 API 说话人识别。

我这样设置识别器:

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();
}

但返回的 JSON 不包含扬声器标签。如何获取也使用 bluemix java API 返回的扬声器标签?

我在 Android 中的录音机如下所示:

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();
        }
    }
}

【问题讨论】:

  • 我认为你的意思是他应该添加语音到文本标签,而不是文本到语音;)
  • @bear 您使用的音频文件和识别方法是什么?你在使用 WebSockets 吗?
  • @bear watson-developer-cloud-java-sdk 版本。
  • @GermanAttanasio: ping,熊已经回答了
  • 是的,我会使用 java-sdk 3.8.0 和你上面的代码。

标签: android ibm-cloud speech-to-text ibm-watson


【解决方案1】:

根据您的示例,我编写了一个示例应用程序并让扬声器标签起作用。

确保您使用的是Java-SDK 4.2.1。在你的build.gradle 添加

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

这是使用 WebSockets、中间结果和扬声器标签识别 assets 文件夹中的 WAV file 的代码的 sn-p。

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());
    }
});

loadInputStreamFromAssetFile() 在哪里:

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;
}

应用程序日志:

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: }]

【讨论】:

    猜你喜欢
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 2014-05-05
    相关资源
    最近更新 更多