安卓上的长音频语音识别

4
我希望开发一个在Android上支持语音转文字的模块。我找到了很多与RecognizerIntent相关的文档和演示。但是我发现这些演示只能提取10秒左右的语音。但我想让我的演示运行超过5-10分钟。如果无法离线运行,我不会有任何问题,因为我的应用程序始终在线工作。
我还看了Android上的Pocketsphinx,但并没有得到很好的支持。而且,它只支持Android Studio,而不支持Eclipse。
我看到很多应用程序可以连续将语音转化为文字5-10分钟,例如:Speech To Text Notepad
请问有人可以推荐其他库或演示代码来实现这个功能吗?谢谢!

离题的资源请求不被允许。你需要尝试重新表述你的问题。 - Mogsdad
3个回答

4
请参考这篇 Android 自定义活动中的语音识别
尝试覆盖方法onEndOfSpeech,并使用代码speechRecognizer.startListening(recognizerIntent)重新启动服务。
我得到了与你引用的应用程序语音转文字记事本相同的结果,以下是我的活动。
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);
    }


}

0
一般来说,长音频语音识别是一个具有挑战性的问题,因此你几乎找不到任何开放的解决方案。相反,我建议您应用其中一种音频分割算法并将其分别识别。此外,如果您有文本转录与音频一起,并且只想获得时间框架(例如视频字幕问题),那么任务变得更加容易,您可以尝试使用长音频对齐

在您提供的有关Pocketsphinx的相同链接中,写道“我们不再支持Eclipse项目,请考虑SDK升级。” - Name is Nilay
你说得对。很抱歉,看起来最近支持已经被取消了。 - Alexander Solovets

-1

我已经成功地借助Google Cloud Speech API完成了这个任务。他们还在这里添加了一个演示。

Google Cloud语音转文字API可以让开发者通过一个易于使用的API将音频转换为文本,应用强大的神经网络模型。该API支持120种语言和变体,以支持您的全球用户群。您可以启用语音命令和控制、转录呼叫中心的音频等功能。它可以使用Google的机器学习技术处理实时流或预先录制的音频。

您可以将用户通过应用程序麦克风口述的文本转录下来,通过语音启用命令和控制,或转录音频文件,以及其他许多用例。通过使用Google用于驱动其自己产品的相同技术,识别请求中上传的音频,并与您在Google Cloud存储上的音频存储集成。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接