Android Bluemix 不显示扬声器标签

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

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

我这样设置识别器:

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 不包含 speaker 标签。我怎样才能获得与 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();
        }
    }
}

最佳答案

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

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

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

这是识别 WAV file 的代码 fragment 从 assets 文件夹使用 WebSockets、中间结果和演讲者标签。

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

关于Android Bluemix 不显示扬声器标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44361853/

相关文章:

android-studio - 适用于 Android 工作室的 Bluemix Cloudant gradle 包?

javascript - x-webkit-speech 已弃用。 JS 替代 <input> 的简单语音输入?

Android 在集群标记上打开 InfoWindow

java - 对象存储 - 读取文本文件时出错

android - Android 手机上的 Gmail 同步

database - 如何使用 Kibana 可视化 IBM Databases for Elasticsearch 部署中的数据?

Cmusphinx 西类牙语模型不连贯的转录

audio - Google语音识别API:每个单词的时间戳?

java - 如何使用最新版本的计费客户端正确导入 BillingResponse (billing :2. 0.1)

java - Job Scheduler 有时不会被触发