Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
语音识别器,用于在android中通话时将语音转换为文本_Android_Speech Recognition_Speech To Text_Phone Call_Speech Synthesis - Fatal编程技术网

语音识别器,用于在android中通话时将语音转换为文本

语音识别器,用于在android中通话时将语音转换为文本,android,speech-recognition,speech-to-text,phone-call,speech-synthesis,Android,Speech Recognition,Speech To Text,Phone Call,Speech Synthesis,我一直在寻找一种解决方案,让我在通话中把语音转换成文本。我想将来自扬声器的语音转换为文本,以处理这些数据,生成可行的输出,然后将文本转换为语音,在通话过程中通过麦克风发送给对方 所有这些工作都应该在通话中完成 有人能帮我吗?试试这个 public class Speech extends AppCompatActivity { private TextView txtSpeechInput; private ImageButton btnSpeak; private final int REQ

我一直在寻找一种解决方案,让我在通话中把语音转换成文本。我想将来自扬声器的语音转换为文本,以处理这些数据,生成可行的输出,然后将文本转换为语音,在通话过程中通过麦克风发送给对方

所有这些工作都应该在通话中完成

有人能帮我吗?

试试这个

public class Speech extends AppCompatActivity {

private TextView txtSpeechInput;
private ImageButton btnSpeak;
private final int REQ_CODE_SPEECH_INPUT = 100;

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

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

    // hide the action bar
    getActionBar().hide();

    btnSpeak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            promptSpeechInput();
        }
    });

}

/**
 * Showing google speech input dialog
 */
private void promptSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}

/**
 * Receiving speech input
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

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

                ArrayList<String> result = data
                        .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                txtSpeechInput.setText(result.get(0));
            }
            break;
        }

    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    return true;
}
public class Speech扩展了AppCompative活动{
私有文本视图txtSpeechInput;
专用图像按钮btnSpeak;
专用最终输入要求代码语音输入=100;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtSpeechInput=(TextView)findViewById(R.id.txtSpeechInput);
btnSpeak=(图像按钮)findViewById(R.id.btnSpeak);
//隐藏操作栏
getActionBar().hide();
btnSpeak.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
promptSpeechInput();
}
});
}
/**
*显示谷歌语音输入对话框
*/
私有无效promptSpeechInput(){
意向意向=新意向(识别意向、行动、识别言语);
intent.putExtra(识别器intent.EXTRA_语言_模型,
识别者意图、语言、模型、自由形式);
intent.putExtra(RecognizerIntent.EXTRA_语言,Locale.getDefault());
intent.putExtra(识别器intent.EXTRA\u提示符,
getString(R.string.speech_提示符);
试一试{
startActivityForResult(意图、请求代码、语音输入);
}捕获(ActivityNotFoundException a){
Toast.makeText(getApplicationContext(),
getString(不支持R.string.speech),
吐司。长度(短)。show();
}
}
/**
*接收语音输入
*/
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
开关(请求代码){
案例请求代码语音输入:{
if(resultCode==RESULT\u OK&&null!=数据){
ArrayList结果=数据
.getStringArrayListExtra(识别器意图.额外结果);
txtSpeechInput.setText(result.get(0));
}
打破
}
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
返回true;
}
}

此xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_gradient"
android:orientation="vertical" >

<TextView
    android:id="@+id/txtSpeechInput"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="100dp"
    android:textColor="@color/white"
    android:textSize="26dp"
    android:textStyle="normal" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="60dp"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/btnSpeak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:src="@drawable/ico_mic" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="@string/tap_on_mic"
        android:textColor="@color/white"
        android:textSize="15dp"
        android:textStyle="normal" />
</LinearLayout>

</RelativeLayout>


为什么要投票表决这个问题。如果你尝试了什么,请发布你的代码。不,我没有尝试过任何类型的代码。我一直在先研究。因为我是初学者,不知道如何操作这些东西。