相关疑难解决方法(0)

有没有办法直接使用SpeechRecognizer API进行语音输入?

Android Dev网站提供了使用内置Google语音输入活动进行语音输入的示例.该活动显示带麦克风的预配置弹出窗口并使用其传递结果onActivityResult()

我的问题:有没有办法SpeechRecognizer直接使用该类进行语音输入而不显示固定活动?这将让我构建自己的语音输入活动.

android speech-recognition speech-to-text

22
推荐指数
2
解决办法
3万
查看次数

SpeechRecognizer导致ANR ......我需要Android语音API的帮助

编辑:我应该已经提到过这个,但我在服务中运行此代码.整个应用程序由小部件按钮打开/关闭,没有任何活动.


更新:我尝试将SDK源附加到项目中,这样我就可以更准确地了解发生故障的位置,但从外观来看,只包含公共API,这似乎使它们的用处更少.任何人都可以建议至少一种调试方法来解决这个问题吗?我有点卡住了.


我正在尝试使用Android的语音识别软件包来记录用户语音并将其翻译成文本.不幸的是,当我尝试启动监听时,我收到的ANR错误并未指出任何具体内容.

正如SpeechRecognizer API指示的那样,如果您尝试从主线程调用它,则抛出RuntimeException.这会让我想知道处理是否过于苛刻......但我知道其他应用程序使用Android API就可以实现这一目的,而且它通常非常活泼.

java.lang.RuntimeException: SpeechRecognizer should be used only from the application's main thread

这是我试图从我的服务中调用的代码的一个(修剪过的)示例.这是正确的方法吗?

感谢您抽出宝贵时间提供帮助.这是一个我无法克服的障碍.

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
        "com.domain.app");

SpeechRecognizer recognizer = SpeechRecognizer
        .createSpeechRecognizer(this.getApplicationContext());
RecognitionListener listener = new RecognitionListener() {
    @Override
    public void onResults(Bundle results) {
        ArrayList<String> voiceResults = results
                .getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
        if (voiceResults == null) {
            Log.e(getString(R.string.log_label), "No voice results");
        } else {
            Log.d(getString(R.string.log_label), "Printing matches: ");
            for (String match : voiceResults) {
                Log.d(getString(R.string.log_label), match); …
Run Code Online (Sandbox Code Playgroud)

android speech-to-text android-service

12
推荐指数
2
解决办法
2万
查看次数