Scopri i Voice Reorganization in Android
è possibile implementare come qui sotto:
scrivere il codice di seguito al clic del pulsante evento, che è responsabile per la cottura fuori l'intento voce.
/**
* Instruct the app to listen for user speech input
*/
private void listenToSpeech() {
//start the speech recognition intent passing required data
Intent listenIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//indicate package
listenIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
//message to display while listening
listenIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word!");
//set speech model
listenIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
//specify number of results to retrieve
listenIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);
//start listening
startActivityForResult(listenIntent, VR_REQUEST);
}
Quando l'intento viene richiamato, viene visualizzata la voce trascritta.
/**
* onActivityResults handles:
* - retrieving results of speech recognition listening
* - retrieving result of TTS data check
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//check speech recognition result
if (requestCode == VR_REQUEST && resultCode == RESULT_OK)
{
//store the returned word list as an ArrayList
ArrayList<String> suggestedWords = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
//set the retrieved list to display in the ListView using an ArrayAdapter
wordList.setAdapter(new ArrayAdapter<String> (this, R.layout.word, suggestedWords));
//to open the result in browser
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.co.in/?gws_rd=cr#q="+suggestedWords));
startActivity(intent);
}
//tss code here
//call superclass method
super.onActivityResult(requestCode, resultCode, data);
}
Grazie GrIsHu per il vostro suggerimento. Secondo questa logica posso vedere che sarò in grado di ottenere il risultato nel browser, ma potresti spiegare come usare TTS per il risultato più accurato. Ad esempio, se chiedo quanto tempo è la torre Eiffel, otterrò il risultato nel browser, ma come posso selezionare il risultato su cui utilizzo TTS per la risposta vocale, in modo che il risultato possa essere udibile. – Shashi
Cosa stai cercando di dire che non ti sto prendendo? – GrIsHu
Il modo in cui si fa clic sull'icona di ricerca vocale di google sul dispositivo Android e si fa qualsiasi domanda, il più delle volte visualizza il risultato sullo schermo e comunica la risposta attraverso l'audio (utilizzando la sintesi vocale). Voglio sapere come farlo, fondamentalmente non sono interessato ai risultati visivi, piuttosto ho bisogno che i risultati vengano pronunciati dal dispositivo nello stesso modo in cui avviene in Google Now. Fammi sapere se non sono ancora abbastanza chiaro. – Shashi