TextToSpeech 클래스에 UI가없는 경우 다른 클래스에서 TextToSpeech 클래스를 호출하는 방법 .. 앱에서 Main 클래스가 사용하는 레이아웃이 하나뿐입니다 .. 이제 내 작업은 응용 프로그램은 ANSTextToSpeech App .. UI없이 호출
답변
//decleration
TextToSpeech talker;
Button speakButton;
//onCreate
talker = new TextToSpeech(this, this);
speakButton=new Button(this);
// Check to see if a recognition activity is present
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) {
speakButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startVoiceRecognitionActivity();
}
});
} else {
speakButton.setEnabled(false);
speakButton.setText("Recognizer not present");
}
/**
* Fire an intent to start the speech recognition activity.
*/
private void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handle the results from the recognition activity.
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it could have heard
ArrayList<String> matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
// Toast.makeText(VoiceRecognition.this, matches.get(0), 5000).show();
String device = "Bedroom";
/* mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
matches));
*/
txt.setText(""+matches.get(0));
String host = "http://web2.anzleads.com/Android/nimboPani/web-service.php?tmote=";
String userCommand = URLEncoder.encode(matches.get(0));
String deviceSelected = "&org=" + device;
res = getServerResponse(host + userCommand + deviceSelected);
say(""+ res);
Toast.makeText(VoiceRecognition.this,res ,5000).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
public void say(String text2say){
talker.speak(text2say, TextToSpeech.QUEUE_FLUSH, null);
}
public void onInit(int status) {
// TODO Auto-generated method stub
// say("Hello World");
}
public void onDestroy() {
if (talker != null) {
talker.stop();
talker.shutdown();
}
super.onDestroy();
}
public String getServerResponse(String url)
{
String result = "";
HttpClient hc = new DefaultHttpClient();
HttpResponse hr ;
HttpGet hg = new HttpGet(url);
try
{
hr = hc.execute(hg);
if(hr.getStatusLine().getStatusCode() == 200)
{
HttpEntity he = hr.getEntity();
if (he != null)
{
InputStream is = he.getContent();
result = convertStreamToString(is);
is.close();
}
}
}
catch (Exception e) {
// TODO: handle exception
}
return result;
}
private String convertStreamToString(InputStream instream) {
BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
instream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
@Sodhi 선생님 내가 StartActivity 함수를 사용하지 않는 이유는 내가 대화를 보여주고 싶지 않아 ..이 코드에서 무슨 일이 일어나고 있는지 자세히 설명해 주시겠습니까 ... 감사합니다 – Shah
@ Sodhi Sir I want 응용 프로그램을 데이터베이스에 저장하는 문장 만 말할 수있게 만들 수 있습니다 .. 서버가 아닙니다. 감사합니다. – Shah
이 코드는 기본적으로 음성 위젯에 대한 안드로이드 throgh 텍스트의 음성 인식에 관한 코드입니다 .U 시작 버튼 클릭시이 코드를 실행하면 대화 상자가 나타납니다 & 당신이 말한대로, 자동으로 당신의 말로 된 단어를 text.But로 변환합니다.하지만이 코드는 당신의 요구 사항에 익숙하지 않습니다. 이 문장을 저장하면 특정 문장의 mp3 파일을 안드로이드 및 그 안의 미디어 플레이어 객체와 함께 사용할 수 있습니다. 왜냐하면 나는 특정 어휘 및 문장의 MP3 파일을 사용하는 과거 응용 프로그램에서 이런 상황을 가지고 있기 때문입니다. –
당신은 UI 또는 TextToSpeech를 사용하는 작업을 할 필요가 없습니다 .. 상황에 따라 사용자와 상호 작용 말한다.
- 1. UI가 표시되지 않고 TextToSpeech 활동 호출
- 2. TextToSpeech API에서 다른 클래스의 메서드 호출
- 3. 안드로이드 TextToSpeech
- 4. Android : TextToSpeech Not Working
- 5. TextToSpeech : 서비스가 시작되지 않았습니까?
- 6. TextToSpeech onUterteranceCompleted 버그
- 7. GCMIntentService에서 TextToSpeech 인스턴스화
- 8. jquery UI없이 탭 jquery
- 9. TextToSpeech, playEarcon 및 .wav 파일
- 10. 피커 또는 UI없이 주소록에 액세스
- 11. UI없이 독립 실행 형 Web.API
- 12. UI없이 데이터 형식 가져 오기
- 13. jQuery UI없이 이동 가능한 div
- 14. TextToSpeech setSpeechRate가 작동하지 않거나 변경 중입니다.
- 15. 알파벳의 글자를 발음하기 위해 TextToSpeech 설교하기
- 16. 단락 뒤에 일시 중지하는 방법 textToSpeech
- 17. jQuery UI없이 끌기 위치 가져 오기
- 18. 블록 UI없이 NSXMLParser 및 NSOperation 사용
- 19. 플러그인이나 UI없이 스크롤바를 시뮬레이트 할 수 있습니까?
- 20. 기본 제공 UI없이 Facebook 요청을 직접 수행
- 21. UI없이 .net 응용 프로그램을 만드는 방법
- 22. app 대리자 및 viewDidLoad 두 번 호출
- 23. Google App Engine - Python의 함수 호출
- 24. Cocoa : 다른 클래스의 App Delegate 메소드 호출
- 25. 다른 클래스의 App Delegate 호출 메소드
- 26. C#의 Python app/script 호출
- 27. Cocoa App 크래시 타사 API 호출
- 28. TextToSpeech 용 사용자 지정 언어를 만드는 방법은 무엇입니까?
- 29. Xcode UI없이 애플 스토어에 앱을 빌드하고 배포 할 수 있습니까?
- 30. ipad 또는 iphone에서 UI없이 이메일을 전송하는 대체 방법
100 % 중복 http://stackoverflow.com/questions/4771562/call-texttospeech-activity-without-any-ui-display – asktomsk
@asktomsk Sir 약간의 해결책을 얻고 싶습니다. 일부를 복사하지 않으 셨습니다. 하나 :) .. 그래서 제발 .. :) – Shah