【问题标题】:Speech to Text conversion in AndroidAndroid中的语音到文本转换
【发布时间】:2011-03-09 22:36:45
【问题描述】:

您好,我需要在 android 中进行语音到文本转换的帮助,我已经在谷歌上搜索了一个小时的主题,我找到的每一个帮助都向我展示了如何将文本转换为语音,而不是相反,

http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TextToSpeechActivity.html

上面的两个链接还向我展示了如何将文本转换为语音, 我基本上是在构建一个应用程序来记录用户所说的任何内容,然后将其转换为文本,我在转换音频时遇到问题

请告诉我它是否可能,如果可以,请给我一个链接,

【问题讨论】:

    标签: android


    【解决方案1】:

    使用RecognizerIntent 在您的应用程序中使用语音输入。您可以查看来自 Google 的示例代码 VoiceRecognition

    【讨论】:

    • 嗨,谢谢你的回复,这对我很有帮助,但是你能再帮我一个忙吗,我尝试运行代码并创建了一个具有适当 id 的 xml 我什至设置了 AUDIO_RECORD 的权限但是当我运行时应用程序按钮上没有文本识别器,这意味着我肯定错过了一些硬件许可或其他东西,因为文本到语音的早期工作正常..知道它可能是什么吗???
    • @umer:Intent 使用设备上可用的任何语音识别服务。确保您的设备上安装了“语音搜索”(来自 Android 市场:market.android.com/details?id=com.google.android.voicesearch)。
    • aah,非常感谢您的帮助.. 早上第一件事就是下载并安装它:D 早上 5:30,我的眼睛在燃烧.. 再次感谢。
    • VoiceRecognition 链接重定向到错误的 url
    • @PratikButani 看起来谷歌已经删除/弃用了该演示。谷歌搜索导致这个例子developer.com/ws/android/programming/…
    【解决方案2】:

    这是代码

        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(),
                                "Opps! 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;
            }
    
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多