아래 코드는 안드로이드 애플 리케이션에서 음성을 텍스트로 변환하는 데 사용됩니다. 이 코드는 말하기 버튼을 눌렀을 때 작동하며 말한 내용이 텍스트로 전송됩니다. 음성 기능이 닫히면 텍스트가 표시됩니다. 음성 단추를 다시 누르면 이전 텍스트가 지워지고 새 텍스트가 페이지에 표시됩니다. 내가 원하는 것은 말하기 버튼을 클릭 할 때마다, 나는 그 단어를 페이지에 표시하고 싶습니다. 그런 다음 말하기 버튼을 다시 누르면 단어가 목록 형식의 첫 단어 아래에 나타나기를 원합니다. listview를 사용하려고하는데 어려움을 겪고 있습니다. 여기에 원래 코드와 내가 그것을 listview 만들려고 노력하고 코드입니다. 아무도 도와 줄 수 있습니까?안드로이드 음성으로 목록보기를 사용하여 텍스트
XML :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_toLeftOf="@+id/textView1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="@+id/btnSpeak"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:contentDescription="@string/speak"
android:src="@android:drawable/ic_btn_speak_now" />
<TextView
android:id="@+id/txtText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
코드 : 당신의 onActivityResult를에서
import java.util.ArrayList;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
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(),
"Ops! 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;
}
}
}
}
무엇이 질문입니까? – clauziere
죄송합니다! 더 분명해야했다. 말하기 버튼을 누르고 단어를 말하면 화면에 단어가 나타납니다. 말하기 버튼을 다시 누르면 첫 번째 단어가 사라지고 내가 말한 두 번째 단어가 화면에 나타납니다. 내가하고 싶은 일은 목록에있는 모든 단어를 목록보기에 표시하고 내가 원하는 경우 목록을 지우는 명확한 버튼이 있습니다. 질문은 .. 이것을 할 코드는 무엇입니까? – user1959064