Android上的长音频语音识别

时间:2015-10-26 10:53:53

标签: android speech-recognition speech-to-text pocketsphinx-android

我想开发一个模块,它将在Android中使用语音文本支持。我发现了许多与RecognizerIntent和其他相关的文档和演示。但是我发现所有这些演示只是将声音提取到10秒左右。但我希望我的演示能够运行超过5-10分钟。如果没有离线运行,我没有任何问题,因为我的应用程序始终在线工作。

我也查看了Pocketsphinx on Android,但这并没有很好。此外,它仅支持Android Studio,而不支持Eclipse。

我见过许多应用程序,可以将语音转换为文本连续5-10分钟,例如:Speech To Text Notepad

任何人都可以建议任何其他可以实现此功能的演示代码库吗? TIA。

3 个答案:

答案 0 :(得分:1)

请参阅此Android Speech Recognition Without Dialog In A Custom Activity

尝试覆盖方法 onEndOfSpeech ,然后使用speechRecognizer.startListening(recognizerIntent)重新启动服务

我得到了与您引用Speech To Text Notepad的应用相同的结果, 这是我的活动

import java.util.ArrayList;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.ToggleButton;

public class VoiceRecognitionActivity extends Activity implements
        RecognitionListener {

    private TextView returnedText;
    private ToggleButton toggleButton;
    private ProgressBar progressBar;
    private SpeechRecognizer speech = null;
    private Intent recognizerIntent;
    private String LOG_TAG = "VoiceRecognition";
    String speechString = "";
    boolean spechStarted = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_voice_recognition);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        returnedText = (TextView) findViewById(R.id.textView1);
        progressBar = (ProgressBar) findViewById(R.id.progressBar1);
        toggleButton = (ToggleButton) findViewById(R.id.toggleButton1);

        progressBar.setVisibility(View.INVISIBLE);
        speech = SpeechRecognizer.createSpeechRecognizer(this);
        speech.setRecognitionListener(this);
        recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
                "en");
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                this.getPackageName());
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

        recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,
                true);

        toggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                if (isChecked) {
                    speech.setRecognitionListener(VoiceRecognitionActivity.this);
                    progressBar.setVisibility(View.VISIBLE);
                    progressBar.setIndeterminate(true);
                    speech.startListening(recognizerIntent);
                } else {
                    progressBar.setIndeterminate(false);
                    progressBar.setVisibility(View.INVISIBLE);
                    speech.stopListening();
                    speech.destroy();

                }
            }
        });

    }

    @Override
    protected void onPause() {
        super.onPause();
        if (speech != null) {
            speech.destroy();
            Log.i(LOG_TAG, "destroy");
        }

    }

    @Override
    public void onBeginningOfSpeech() {
        Log.i(LOG_TAG, "onBeginningOfSpeech");
        spechStarted = true;
        progressBar.setIndeterminate(false);
        progressBar.setMax(10);
    }

    @Override
    public void onBufferReceived(byte[] buffer) {
        Log.i(LOG_TAG, "onBufferReceived: " + buffer);
    }

    @Override
    public void onEndOfSpeech() {

        spechStarted = false;
        Log.i(LOG_TAG, "onEndOfSpeech");
        speech.startListening(recognizerIntent);

    }

    @Override
    public void onError(int errorCode) {
        Log.d(LOG_TAG, "FAILED ");
        if (!spechStarted)
            speech.startListening(recognizerIntent);

    }

    @Override
    public void onEvent(int arg0, Bundle arg1) {
        Log.i(LOG_TAG, "onEvent");
    }

    @Override
    public void onPartialResults(Bundle arg0) {
        Log.i(LOG_TAG, "onPartialResults");

        ArrayList<String> matches = arg0
                .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);

        returnedText.setText(speechString + matches.get(0));


    }

    @Override
    public void onReadyForSpeech(Bundle arg0) {
        Log.i(LOG_TAG, "onReadyForSpeech");
    }

    @Override
    public void onResults(Bundle results) {
        Log.i(LOG_TAG, "onResults");
        ArrayList<String> matches = results
                .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
        speechString = speechString + ". " + matches.get(0);
    }

    @Override
    public void onRmsChanged(float rmsdB) {
        Log.i(LOG_TAG, "onRmsChanged: " + rmsdB);
        progressBar.setProgress((int) rmsdB);
    }


}

答案 1 :(得分:0)

通常,长音频语音识别是一个具有挑战性的问题,所以你几乎找不到任何开放的东西。相反,我建议您应用其中一种音频分割算法并单独识别它们。此外,如果您有文字记录和音频,并且只想获得时间范围(例如视频字幕问题),那么任务变得更加容易,您可以尝试long audio alignment

答案 2 :(得分:0)

我在Google Cloud Speech API的帮助下成功完成了这项工作。他们还添加了演示here

Google Cloud Speech-to-Text使开发人员能够通过在易于使用的API中应用强大的神经网络模型将音频转换为文本。 API可识别120种语言和变体,以支持您的全球用户群。您可以启用语音命令和控制,从呼叫中心转录音频等。它可以使用谷歌的机器学习技术处理实时流媒体或预先录制的音频。

您可以将用户的文本转录到应用程序的麦克风,通过语音启用命令和控制,或者  转录音频文件,以及许多其他用例。识别音频  上传到请求中,并与您的音频存储集成  谷歌云存储,采用与谷歌相同的技术  为自己的产品提供动力。