【问题标题】:Transform voice to text on Android在 Android 上将语音转换为文本
【发布时间】:2016-07-03 07:23:27
【问题描述】:

我是 Android 新手,我必须做一个项目,我需要在其中创建一个可用于获取语音命令的应用程序。我需要录制用户的声音,将其保存为音频文件然后转换为文本或直接将其转换为文本文件而不保存音频文件。

这是我迄今为止所做的,

public class VoiceRecognitionDemo extends Activity{

    private static final int REQUEST_CODE = 1234;
    private ListView wordsList;

    /**
     * Called with the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.voice_recog);

        Button speakButton = (Button) findViewById(R.id.speakButton);

        wordsList = (ListView) findViewById(R.id.list);

        // Disable button if no recognition service is present
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
        if (activities.size() == 0)
        {
            speakButton.setEnabled(false);
            speakButton.setText("Recognizer not present");
        }
    }

    /**
     * Handle the action of the button being clicked
     */
    public void speakButtonClicked(View v)
    {
        startVoiceRecognitionActivity();
    }

    /**
     * Fire an intent to start the voice recognition activity.
     */
    private void startVoiceRecognitionActivity()
    {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
        startActivityForResult(intent, REQUEST_CODE);
    }

    /**
     * Handle the results from the voice recognition activity.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
        {
            // Populate the wordsList with the String values the recognition engine thought it heard
            ArrayList<String> matches = data.getStringArrayListExtra(
                    RecognizerIntent.EXTRA_RESULTS);
            wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                    matches));
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}

我需要对该数组进行排序以提取某些关键字来触发操作。如何触发某些操作(例如 - 在短语呼叫、交谈时发起呼叫)?

【问题讨论】:

  • 构建 Siri 或 Google Voice 可能有点困难。
  • 我知道 :( 但这是我必须做的事情,不像他们那么先进。但非常简单的一个
  • 你可以从这里开始——语音转文字教程:androidhive.info/2014/07/android-speech-to-text-tutorial
  • 我试过那个。但它没有在我的手机或我朋友的手机上成功运行。我不知道出了什么问题。有时它甚至无法安装。感谢 MorZa 的链接

标签: java android speech-recognition


【解决方案1】:

您可以使用Nuance SDK 识别语音转文本。它是一个跨平台的 SDK,支持 40 多种语言。此 SDK 不是免费的,但您可以使用有效期为 30 天的测试密钥。

您可以将音频文件或流发送到 Nuance 服务器。作为响应,您将获得一个文本字符串。然后你就可以实现自己的获取关键字和命令的逻辑了。

【讨论】:

  • 感谢 matway 的帮助。我检查了细微差别。但它对我来说有点困难。无论如何我可以在 android 上使用谷歌自己的预构建的东西吗?如果你知道请帮忙
  • 嗯...我只使用了 nuance sdk,但经过一番搜索,我找到了两个对您的问题感兴趣的答案:firstsecond。我没有时间自己测试那个代码,但它看起来很简单,我希望你可以通过这种方式使用原生谷歌语音识别。
  • 非常感谢您的帮助。我会试一试 :) 如果我遇到任何问题会回来。感谢所有帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-09
  • 1970-01-01
  • 1970-01-01
  • 2020-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多