1
내가 코딩 한 간단한 음성 인식 앱이 예상대로 작동하지 않습니다. 기본적으로 로그에는 눈에 띄는 오류가 없으며 정상적으로 컴파일되지만 버튼을 클릭하면 음성 인식 기능이 팝업되어 녹음을 시작하지만 녹음이 끝나면 listview가 표시되어야하는 앱 화면에 아무 것도 표시되지 않습니다. 어떤 여기android의 간단한 음성 인식 앱이 예상대로 작동하지 않습니다.
(텍스트 형식) 기록 된 것은 여기에 자바 코드를
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import java.util.ArrayList;
public class Voice extends Activity implements View.OnClickListener {
ListView lv;
final static int check = 1111;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.voice);
lv = (ListView) findViewById(R.id.lvVoiceReturn);
Button b = (Button) findViewById(R.id.bVoice);
b.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // set speech recognizer intent
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); //set language
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak up son!"); // set prompt to user
startActivityForResult(i, check);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == check && resultCode == RESULT_OK) {
// create an empty array list and link it to the recognizer intent
ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
// link the listview from my layout to the arraylist I created just now with the results from voice recognition
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results));
}
}
}
입니다 그리고 것은
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/bVoice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click to Speak" />
<ListView
android:id="@+id/lvVoiceReturn"
android:layout_width="match_parent"
android:layout_height="fill_parent" />
</LinearLayout>
덕분에 XML 레이아웃을입니다!
실수를 저지른 경우. 나는 인터넷에 연결되어 있지 않았다. 이제 앱이 작동하고 음 성 인식에 연결이 필요합니다. 하지만 고마워! – Kalid