java - 我可以从语音识别中获取语音数据(例如 mp3 格式)吗?

标签 java android speech-recognition voice-recognition speech-to-text

<分区>

Possible Duplicate:
Android: Voice Recording and saving audio

我是说;

我在 android 上使用语音识别类,并且我成功地进行了语音识别。 但我想要真正的语音数据而不是文字。 例如,我说 'teacher' 并且 android 让你说老师。哦,好的,但我想要我的声音,其中包括 'teacher'。它在哪里?我可以把它保存到另一个位置吗?

我用这个类来语音转文本:

package net.viralpatel.android.speechtotextdemo;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    protected static final int RESULT_SPEECH = 1;

    private ImageButton btnSpeak;
    private TextView txtText;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txtText = (TextView) findViewById(R.id.txtText);

        btnSpeak = (ImageButton) findViewById(R.id.btnSpeak);

        btnSpeak.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent = new Intent(
                        RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

                try {
                    startActivityForResult(intent, RESULT_SPEECH);
                    txtText.setText("");
                } catch (ActivityNotFoundException a) {
                    Toast t = Toast.makeText(getApplicationContext(),
                            "Ops! Your device doesn't support Speech to Text",
                            Toast.LENGTH_SHORT);
                    t.show();
                }
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
        case RESULT_SPEECH: {
            if (resultCode == RESULT_OK && null != data) {

                ArrayList<String> text = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

                txtText.setText(text.get(0));
            }
            break;
        }

        }
    }
}

谢谢。

最佳答案

所以你想使用 Android speech recognition API获取用户所说内容的转录和音频。我所知道的唯一解决方案是使用 SpeechRecognizer 类。这允许您与系统上安装的语音识别器进行交互,但您必须自己实现 UI(麦克风按钮、错误消息显示等)。因此,它比使用普通的 RecognizerIntent.ACTION_RECOGNIZE_SPEECH 要多一些工作。您案例中的相关类/方法是:

请注意,最后一个方法的文档包括不能保证会调用此方法,因此语音识别 API 并非真正设计为允许音频捕获。它还说采样率取决于实现。,即您甚至不知道如何播放音频(或将其保存为 wav)。

另见答案 https://stackoverflow.com/a/10918416/12547

总结:

  • Android 语音识别 API 返回 MP3
  • Android 语音识别 API 不会将任何内容写入 SD 卡
  • Android 语音识别 API 包含一个以字节数组形式返回音频的方法,但您不能依赖每个语音识别应用来实现此方法

关于java - 我可以从语音识别中获取语音数据(例如 mp3 格式)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13217100/

相关文章:

android - 禁用/覆盖 Cordova 3.5 中的 Android 后退按钮

machine-learning - HTK:了解生成的 .mlf 文件中的分数

python - 您如何使用 Python 模块 Dragonfly 识别语音?

java - 分割字符

java - 将 Java 库导入 Eclipse

java - 确保对象始终是列表的成员?

python - 谷歌语音识别模块在我尝试时抛出错误

java - 如果满足某些条件,如何防止进入 while 循环?

php - Android:UTF-8 编码的 HttpPost JSON 字符串到 PHP

android - 如何检查可观察对象中的空数组?