/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/NavitSpeech2.java
ZANavi

Diff of /navit/navit/android/src/com/zoffcc/applications/zanavi/NavitSpeech2.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 40 Revision 41
65 float debug_lat = 0; 65 float debug_lat = 0;
66 float debug_lon = 0; 66 float debug_lon = 0;
67 HashMap<String, String> tts_params = new HashMap<String, String>(); 67 HashMap<String, String> tts_params = new HashMap<String, String>();
68 68
69 @SuppressWarnings("deprecation") 69 @SuppressWarnings("deprecation")
70 public void onInit(int status) 70 public void onInit(final int status)
71 {
72 tts_params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "ZANaviUtterID");
73
74 Log.e("NavitSpeech2", "onInit: Status " + status);
75 int result = -1;
76 try
77 { 71 {
78 // set the new locale here ----------------------------------- 72 if (status == TextToSpeech.SUCCESS)
79 Locale locale2 = want_locale;
80 Locale.setDefault(locale2);
81 Configuration config2 = new Configuration();
82 config2.locale = locale2;
83 // set the new locale here -----------------------------------
84 try
85 { 73 {
86 result = navit.mTts.setLanguage(locale2); 74 new Thread(new Runnable()
87 }
88 catch (Exception e)
89 {
90 e.printStackTrace();
91 }
92
93 try
94 {
95 Log.e("NavitSpeech2", "3.1 want locale=" + locale2.getLanguage());
96 //Log.e("NavitSpeech2", "3 E=" + navit.mTts.getDefaultEngine());
97 //Log.e("NavitSpeech2", "3 def.enf.=" + navit.mTts.areDefaultsEnforced());
98 }
99 catch (NoSuchMethodError e2)
100 {
101 e2.printStackTrace();
102 }
103 catch (Exception e)
104 {
105 e.printStackTrace();
106 }
107
108 try
109 {
110 Log.e("NavitSpeech2", "3 lang. Country=" + navit.mTts.getLanguage().getDisplayCountry());
111 Log.e("NavitSpeech2", "3 lang. Country=" + navit.mTts.getLanguage().getDisplayLanguage());
112 Log.e("NavitSpeech2", "3 lang. Country=" + navit.mTts.getLanguage().getDisplayName());
113 Log.e("NavitSpeech2", "3 lang. Country=" + navit.mTts.getLanguage().getDisplayVariant());
114 }
115 catch (NoSuchMethodError e2)
116 {
117 e2.printStackTrace();
118 }
119 catch (Exception e)
120 {
121 e.printStackTrace();
122 }
123
124 String want_lang_code = locale2.getISO3Language();
125 Log.e("NavitSpeech2", "want:" + want_lang_code);
126 String will_use_lang_code = navit.mTts.getLanguage().getISO3Language();
127 Log.e("NavitSpeech2", "will use:" + will_use_lang_code);
128 if (want_lang_code.compareToIgnoreCase(will_use_lang_code) != 0)
129 {
130 result = TextToSpeech.LANG_NOT_SUPPORTED;
131 }
132
133 Log.e("NavitSpeech2", "3 ok result=" + result);
134 }
135 catch (Exception e1)
136 { 75 {
137 e1.printStackTrace(); 76 public void run()
138 result = TextToSpeech.LANG_NOT_SUPPORTED;
139 }
140
141 try
142 {
143 navit.mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener()
144 {
145
146 @Override
147 public void onUtteranceCompleted(String utteranceId)
148 { 77 {
78
149 try 79 try
150 { 80 {
81 tts_params.clear();
82 }
83 catch (Exception e)
84 {
85 }
86
87 try
88 {
89 tts_params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "ZANaviUtterID");
90 }
91 catch (Exception e)
92 {
93 }
94
95 Log.e("NavitSpeech2", "onInit: Status " + status);
96 int result = -1;
97 try
98 {
99 // set the new locale here -----------------------------------
100 Locale locale2 = want_locale;
101 Locale.setDefault(locale2);
102 Configuration config2 = new Configuration();
103 config2.locale = locale2;
104 // set the new locale here -----------------------------------
105 try
106 {
107 result = navit.mTts.setLanguage(locale2);
108 }
109 catch (Exception e)
110 {
111 e.printStackTrace();
112 }
113
114 try
115 {
116 Log.e("NavitSpeech2", "3.1 want locale=" + locale2.getLanguage());
117 //Log.e("NavitSpeech2", "3 E=" + navit.mTts.getDefaultEngine());
118 //Log.e("NavitSpeech2", "3 def.enf.=" + navit.mTts.areDefaultsEnforced());
119 }
120 catch (NoSuchMethodError e2)
121 {
122 e2.printStackTrace();
123 }
124 catch (Exception e)
125 {
126 e.printStackTrace();
127 }
128
129 try
130 {
131 Log.e("NavitSpeech2", "3 lang. Country=" + navit.mTts.getLanguage().getDisplayCountry());
132 Log.e("NavitSpeech2", "3 lang. Country=" + navit.mTts.getLanguage().getDisplayLanguage());
133 Log.e("NavitSpeech2", "3 lang. Country=" + navit.mTts.getLanguage().getDisplayName());
134 Log.e("NavitSpeech2", "3 lang. Country=" + navit.mTts.getLanguage().getDisplayVariant());
135 }
136 catch (NoSuchMethodError e2)
137 {
138 e2.printStackTrace();
139 }
140 catch (Exception e)
141 {
142 e.printStackTrace();
143 }
144
145 String want_lang_code = locale2.getISO3Language();
146 Log.e("NavitSpeech2", "want:" + want_lang_code);
147 String will_use_lang_code = navit.mTts.getLanguage().getISO3Language();
148 Log.e("NavitSpeech2", "will use:" + will_use_lang_code);
149 if (want_lang_code.compareToIgnoreCase(will_use_lang_code) != 0)
150 {
151 result = TextToSpeech.LANG_NOT_SUPPORTED;
152 }
153
154 Log.e("NavitSpeech2", "3 ok result=" + result);
155 }
156 catch (Exception e1)
157 {
158 e1.printStackTrace();
159 result = TextToSpeech.LANG_NOT_SUPPORTED;
160 }
161
162 try
163 {
164 navit.mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener()
165 {
166
167 @Override
168 public void onUtteranceCompleted(String utteranceId)
169 {
170 try
171 {
151 if (need_audio_focus == 0) 172 if (need_audio_focus == 0)
152 { 173 {
153 Navit.NavitAudioManager.abandonAudioFocus(Navit.focusChangeListener); 174 Navit.NavitAudioManager.abandonAudioFocus(Navit.focusChangeListener);
175 }
154 } 176 }
155 }
156 catch (Exception e44) 177 catch (Exception e44)
157 { 178 {
158 } 179 }
159 // runOnUiThread(new Runnable() 180 // runOnUiThread(new Runnable()
160 // { 181 // {
161 // 182 //
162 // @Override 183 // @Override
163 // public void run() 184 // public void run()
164 // { 185 // {
165 // //UI changes 186 // //UI changes
166 // } 187 // }
167 // }); 188 // });
189 }
190 });
191 }
192 catch (Exception e77)
193 {
194 e77.printStackTrace();
195 }
196
197 if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
198 {
199 // Lanuage data is missing or the language is not supported.
200 Log.e("NavitSpeech2", "3 Language is not available.");
201
202 try
203 {
204 // lang for TTS not found, show toast
205 Message msg = Navit.Navit_progress_h.obtainMessage();
206 Bundle b = new Bundle();
207 msg.what = 2;
208 b.putString("text", Navit.get_text("Language is not available for TTS! Using your phone's default settings")); //TRANS
209 msg.setData(b);
210 Navit.Navit_progress_h.sendMessage(msg);
211 }
212 catch (Exception e1)
213 {
214 e1.printStackTrace();
215 }
216 }
217 else
218 {
219 try
220 {
221 // lang for TTS not found, show toast
222 Message msg = Navit.Navit_progress_h.obtainMessage();
223 Bundle b = new Bundle();
224 msg.what = 2;
225 b.putString("text", Navit.get_text("Using Voice for:") + "\n" + navit.mTts.getLanguage().getDisplayName()); //TRANS
226 msg.setData(b);
227 Navit.Navit_progress_h.sendMessage(msg);
228 }
229 catch (Exception e1)
230 {
231 e1.printStackTrace();
232 }
233 }
234
168 } 235 }
169 }); 236 }).start();
170 }
171 catch (Exception e77)
172 {
173 e77.printStackTrace();
174 }
175 237
176 if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
177 {
178 // Lanuage data is missing or the language is not supported.
179 Log.e("NavitSpeech2", "3 Language is not available.");
180
181 try
182 {
183 // lang for TTS not found, show toast
184 Message msg = Navit.Navit_progress_h.obtainMessage();
185 Bundle b = new Bundle();
186 msg.what = 2;
187 b.putString("text", Navit.get_text("Language is not available for TTS! Using your phone's default settings")); //TRANS
188 msg.setData(b);
189 Navit.Navit_progress_h.sendMessage(msg);
190 }
191 catch (Exception e1)
192 {
193 e1.printStackTrace();
194 }
195 }
196 else
197 {
198 try
199 {
200 // lang for TTS not found, show toast
201 Message msg = Navit.Navit_progress_h.obtainMessage();
202 Bundle b = new Bundle();
203 msg.what = 2;
204 b.putString("text", Navit.get_text("Using Voice for:") + "\n" + navit.mTts.getLanguage().getDisplayName()); //TRANS
205 msg.setData(b);
206 Navit.Navit_progress_h.sendMessage(msg);
207 }
208 catch (Exception e1)
209 {
210 e1.printStackTrace();
211 }
212 } 238 }
213 } 239 }
214 240
215 public void onActivityResult(int requestCode, int resultCode, Intent data) 241 public void onActivityResult(int requestCode, int resultCode, Intent data)
216 { 242 {
292 318
293 @SuppressLint("NewApi") 319 @SuppressLint("NewApi")
294 public void say(String what, int lat, int lon) 320 public void say(String what, int lat, int lon)
295 { 321 {
296 322
297 if (Navit.PREF_enable_debug_write_gpx) 323 if (Navit.p.PREF_enable_debug_write_gpx)
298 { 324 {
299 // ------- SPEECH DEBUG ------------------------------- 325 // ------- SPEECH DEBUG -------------------------------
300 // ------- SPEECH DEBUG ------------------------------- 326 // ------- SPEECH DEBUG -------------------------------
301 // ------- SPEECH DEBUG ------------------------------- 327 // ------- SPEECH DEBUG -------------------------------
302 if ((lat != 0) || (lon != 0)) 328 if ((lat != 0) || (lon != 0))
340 } 366 }
341 catch (Exception e33) 367 catch (Exception e33)
342 { 368 {
343 } 369 }
344 370
345 if (Navit.PREF_speak_filter_special_chars) 371 if (Navit.p.PREF_speak_filter_special_chars)
346 { 372 {
347 what = filter_out_special_chars(what); 373 what = filter_out_special_chars(what);
348 } 374 }
349 375
350 what = filter_out_special_chars_google(what); 376 what = filter_out_special_chars_google(what);
370 if (NavitGraphics.NavitMsgTv2_.getVisibility() == View.VISIBLE) 396 if (NavitGraphics.NavitMsgTv2_.getVisibility() == View.VISIBLE)
371 { 397 {
372 Navit.set_debug_messages_say_wrapper("SAY:" + what + "\n"); 398 Navit.set_debug_messages_say_wrapper("SAY:" + what + "\n");
373 } 399 }
374 400
375 if (Navit.PREF_show_debug_messages) 401 if (Navit.p.PREF_show_debug_messages)
376 { 402 {
377 Navit.set_debug_messages3_wrapper(what); 403 Navit.set_debug_messages3_wrapper(what);
378 } 404 }
379 } 405 }
380 } 406 }

Legend:
Removed from v.40  
changed lines
  Added in v.41

   
Visit the ZANavi Wiki