2011-07-11 17 views
8

मैंने विभिन्न भाषाओं में टीटीएस का उपयोग करने के लिए एक छोटा एंड्रॉइड डेमो लिखा है। मेरे पास दो बटन, स्पेनिश और अंग्रेजी के साथ एक लेआउट है। बटन दबाकर चयनित भाषा में एक उच्चारण ट्रिगर करता है।टीटीएस प्रोग्रामेटिक रूप से भाषा सेट करना?

हालांकि, मैं भाषा (सेट भाषा (लोकेल लोकेल) नहीं बदल सकता)। मैं इसे फोन सेटिंग्स का उपयोग करके और टीटीएस भाषा को यूएस, यूके, इटालियन, जर्मन इत्यादि में बदलकर हाथ से कर सकता हूं, लेकिन मेरा कोड काम नहीं कर रहा है। क्या आप मुझे बता सकते हैं कि समस्या कहां है?

धन्यवाद !!

package com.ignacio.SpeakAPP; 

import android.app.Activity; 
import android.os.Bundle; 
import android.speech.tts.TextToSpeech; 
import android.speech.tts.TextToSpeech.OnInitListener; 
import android.util.Log; 
import android.view.View; 
import java.util.Locale; 

public class SpeakAPPActivity extends Activity implements OnInitListener { 
private static final String TAG = "TextToSpeechDemo"; 
private TextToSpeech mTts; 
public boolean Passer = false; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
} 

/** Handle the action of the English Button **/ 
public boolean talknowEN(View v) 
{ 

    mTts = new TextToSpeech (this, this); 
    return Passer = false; 
} 

/** Handle the action of the Spanish Button **/ 
public boolean talknowES(View v) 
{ 
    mTts = new TextToSpeech (this, this); 
    return Passer = true; 
} 

/** TTS **/ 
public void onInit (int status){ 

    if (status ==TextToSpeech.SUCCESS){ 

     if(Passer==false){ 
      //If English Button was activated 
      //Initialize speech to text, set language to english and send utterance 
      mTts.setLanguage(Locale.US); 
      mTts.speak("How may I help you?", TextToSpeech.QUEUE_FLUSH, null); 
     }else{ 
      //If Spanish Button was activated 
      //Initialize speech to text, check if spanish is available, set locale to spanish and send utterance 

      Locale loc = new Locale ("es", "ES"); 
      mTts.setLanguage(loc); 
      if (result2==TextToSpeech.LANG_MISSING_DATA||result2==TextToSpeech.LANG_NOT_SUPPORTED){ 
       Log.e(TAG, "Language is not available"); 
      }else { 
       mTts.speak("Como puedo ayudarte?", TextToSpeech.QUEUE_FLUSH, null); 
      } 

     } 

    }else { 
     Log.e(TAG, "Could not initialize TextToSpeech"); 
    } 

} 


@Override 
protected void onDestroy(){ 
    super.onDestroy(); 
    mTts.shutdown(); 
} 

}

उत्तर

5

https://web.archive.org/web/20120505124037/http://developer.android.com/resources/articles/tts.html से, आप इस की कोशिश करना चाहते हो सकता है:

Locale loc = new Locale ("spa", "ESP"); 

अजीब लगता है, लेकिन है कि वे क्या संदर्भ है (नहीं es की तरह एक उम्मीद होती है)।

+0

धन्यवाद फेमी, मैंने कोशिश की लेकिन यह भी काम नहीं कर रहा है: एस – Ignacio

+4

मैंने अंततः समस्या को हल किया! मुझे टेक्स्ट टू स्पीच सेटिंग्स के तहत "हमेशा मेरी सेटिंग्स का उपयोग करें" चेकबॉक्स को मैन्युअल रूप से अनचेक करना पड़ा। – Ignacio

+0

@Ignacio जहां मैं सैमसंग गैलेक्सी एस 3 –

संबंधित मुद्दे