eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VoiceSettingsTest.java 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * Copyright (C) 2013 Reece H. Dunn
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.reecedunn.espeak.test;
  17. import android.content.SharedPreferences;
  18. import android.preference.PreferenceManager;
  19. import com.reecedunn.espeak.SpeechSynthesis;
  20. import com.reecedunn.espeak.VoiceSettings;
  21. import org.json.JSONException;
  22. import org.json.JSONObject;
  23. import static org.hamcrest.MatcherAssert.assertThat;
  24. import static org.hamcrest.Matchers.*;
  25. public class VoiceSettingsTest extends TextToSpeechTestCase
  26. {
  27. private SpeechSynthesis.SynthReadyCallback mCallback = new SpeechSynthesis.SynthReadyCallback()
  28. {
  29. @Override
  30. public void onSynthDataReady(byte[] audioData)
  31. {
  32. }
  33. @Override
  34. public void onSynthDataComplete()
  35. {
  36. }
  37. };
  38. // No Settings (New Install)
  39. public void testNoPreferences()
  40. {
  41. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  42. SharedPreferences.Editor editor = prefs.edit();
  43. editor.clear();
  44. editor.commit();
  45. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  46. VoiceSettings settings = new VoiceSettings(prefs, synth);
  47. assertThat(settings.getVoiceVariant().toString(), is("male"));
  48. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  49. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  50. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  51. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  52. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  53. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  54. try {
  55. JSONObject json = settings.toJSON();
  56. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  57. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  58. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  59. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  60. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  61. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  62. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  63. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  64. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  65. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  66. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  67. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  68. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  69. } catch (JSONException e) {
  70. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  71. }
  72. }
  73. // Old Settings
  74. public void testDefaultGenderMale()
  75. {
  76. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  77. SharedPreferences.Editor editor = prefs.edit();
  78. editor.clear();
  79. editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_MALE));
  80. editor.commit();
  81. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  82. VoiceSettings settings = new VoiceSettings(prefs, synth);
  83. assertThat(settings.getVoiceVariant().toString(), is("male"));
  84. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  85. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  86. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  87. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  88. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  89. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  90. try {
  91. JSONObject json = settings.toJSON();
  92. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  93. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  94. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  95. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  96. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  97. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  98. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  99. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  100. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  101. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  102. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  103. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  104. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  105. } catch (JSONException e) {
  106. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  107. }
  108. }
  109. public void testDefaultGenderFemale()
  110. {
  111. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  112. SharedPreferences.Editor editor = prefs.edit();
  113. editor.clear();
  114. editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_FEMALE));
  115. editor.commit();
  116. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  117. VoiceSettings settings = new VoiceSettings(prefs, synth);
  118. assertThat(settings.getVoiceVariant().toString(), is("female"));
  119. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  120. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  121. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  122. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  123. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  124. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  125. try {
  126. JSONObject json = settings.toJSON();
  127. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  128. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("female"));
  129. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  130. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  131. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  132. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  133. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  134. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  135. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  136. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  137. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  138. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  139. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  140. } catch (JSONException e) {
  141. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  142. }
  143. }
  144. public void defaultRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
  145. {
  146. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  147. SharedPreferences.Editor editor = prefs.edit();
  148. editor.clear();
  149. editor.putString("default_rate", Integer.toString(prefValue));
  150. editor.commit();
  151. VoiceSettings settings = new VoiceSettings(prefs, synth);
  152. assertThat(settings.getVoiceVariant().toString(), is("male"));
  153. assertThat(settings.getRate(), is(settingValue));
  154. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  155. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  156. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  157. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  158. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  159. try {
  160. JSONObject json = settings.toJSON();
  161. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  162. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  163. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  164. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(settingValue));
  165. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  166. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  167. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  168. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  169. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  170. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  171. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  172. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  173. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  174. } catch (JSONException e) {
  175. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  176. }
  177. }
  178. public void testDefaultRate()
  179. {
  180. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  181. defaultRateTest(300, 449, synth); // clamped to maximum value
  182. defaultRateTest(200, 350, synth);
  183. defaultRateTest(100, 175, synth); // default value
  184. defaultRateTest( 50, 87, synth);
  185. defaultRateTest( 25, 80, synth); // clamped to minimum value
  186. }
  187. public void defaultPitchTest(int prefValue, int settingValue, SpeechSynthesis synth)
  188. {
  189. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  190. SharedPreferences.Editor editor = prefs.edit();
  191. editor.clear();
  192. editor.putString("default_pitch", Integer.toString(prefValue));
  193. editor.commit();
  194. VoiceSettings settings = new VoiceSettings(prefs, synth);
  195. assertThat(settings.getVoiceVariant().toString(), is("male"));
  196. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  197. assertThat(settings.getPitch(), is(settingValue));
  198. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  199. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  200. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  201. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  202. try {
  203. JSONObject json = settings.toJSON();
  204. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  205. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  206. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  207. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  208. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  209. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(settingValue));
  210. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  211. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  212. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  213. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  214. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  215. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  216. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  217. } catch (JSONException e) {
  218. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  219. }
  220. }
  221. public void testDefaultPitch()
  222. {
  223. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  224. defaultPitchTest(250, 100, synth); // clamped to maximum value
  225. defaultPitchTest(200, 100, synth);
  226. defaultPitchTest(100, 50, synth); // default value
  227. defaultPitchTest( 50, 25, synth);
  228. defaultPitchTest( 0, 0, synth);
  229. defaultPitchTest( -5, 0, synth); // clamped to minimum value
  230. }
  231. // New Settings
  232. public void testEspeakVariant()
  233. {
  234. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  235. SharedPreferences.Editor editor = prefs.edit();
  236. editor.clear();
  237. editor.putString("espeak_variant", "klatt2-old");
  238. editor.commit();
  239. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  240. VoiceSettings settings = new VoiceSettings(prefs, synth);
  241. assertThat(settings.getVoiceVariant().toString(), is("klatt2-old"));
  242. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  243. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  244. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  245. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  246. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  247. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  248. try {
  249. JSONObject json = settings.toJSON();
  250. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  251. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("klatt2-old"));
  252. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  253. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  254. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  255. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  256. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  257. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  258. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  259. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  260. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  261. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  262. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  263. } catch (JSONException e) {
  264. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  265. }
  266. }
  267. public void espeakRateTest(int prefValue, int settingValue, SpeechSynthesis synth)
  268. {
  269. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  270. SharedPreferences.Editor editor = prefs.edit();
  271. editor.clear();
  272. editor.putString("espeak_rate", Integer.toString(prefValue));
  273. editor.commit();
  274. VoiceSettings settings = new VoiceSettings(prefs, synth);
  275. assertThat(settings.getVoiceVariant().toString(), is("male"));
  276. assertThat(settings.getRate(), is(settingValue));
  277. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  278. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  279. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  280. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  281. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  282. try {
  283. JSONObject json = settings.toJSON();
  284. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  285. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  286. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  287. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(settingValue));
  288. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  289. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  290. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  291. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  292. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  293. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  294. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  295. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  296. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  297. } catch (JSONException e) {
  298. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  299. }
  300. }
  301. public void testEspeakRate()
  302. {
  303. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  304. espeakRateTest(500, 449, synth); // clamped to maximum value
  305. espeakRateTest(400, 400, synth);
  306. espeakRateTest(200, 200, synth);
  307. espeakRateTest(175, 175, synth); // default value
  308. espeakRateTest(150, 150, synth);
  309. espeakRateTest( 70, 80, synth); // clamped to minimum value
  310. }
  311. public void espeakPitchTest(int prefValue, int settingValue, SpeechSynthesis synth)
  312. {
  313. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  314. SharedPreferences.Editor editor = prefs.edit();
  315. editor.clear();
  316. editor.putString("espeak_pitch", Integer.toString(prefValue));
  317. editor.commit();
  318. VoiceSettings settings = new VoiceSettings(prefs, synth);
  319. assertThat(settings.getVoiceVariant().toString(), is("male"));
  320. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  321. assertThat(settings.getPitch(), is(settingValue));
  322. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  323. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  324. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  325. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  326. try {
  327. JSONObject json = settings.toJSON();
  328. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  329. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  330. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  331. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  332. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  333. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(settingValue));
  334. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  335. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  336. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  337. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  338. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  339. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  340. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  341. } catch (JSONException e) {
  342. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  343. }
  344. }
  345. public void testEspeakPitch()
  346. {
  347. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  348. espeakPitchTest(110, 100, synth); // clamped to maximum value
  349. espeakPitchTest(100, 100, synth);
  350. espeakPitchTest( 50, 50, synth); // default value
  351. espeakPitchTest( 10, 10, synth);
  352. espeakPitchTest( -5, 0, synth); // clamped to minimum value
  353. }
  354. public void espeakPitchRangeTest(int prefValue, int settingValue, SpeechSynthesis synth)
  355. {
  356. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  357. SharedPreferences.Editor editor = prefs.edit();
  358. editor.clear();
  359. editor.putString("espeak_pitch_range", Integer.toString(prefValue));
  360. editor.commit();
  361. VoiceSettings settings = new VoiceSettings(prefs, synth);
  362. assertThat(settings.getVoiceVariant().toString(), is("male"));
  363. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  364. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  365. assertThat(settings.getPitchRange(), is(settingValue));
  366. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  367. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  368. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  369. try {
  370. JSONObject json = settings.toJSON();
  371. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  372. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  373. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  374. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  375. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  376. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  377. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  378. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(settingValue));
  379. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  380. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  381. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  382. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  383. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  384. } catch (JSONException e) {
  385. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  386. }
  387. }
  388. public void testEspeakPitchRange()
  389. {
  390. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  391. espeakPitchRangeTest(110, 100, synth); // clamped to maximum value
  392. espeakPitchRangeTest(100, 100, synth);
  393. espeakPitchRangeTest( 50, 50, synth); // default value
  394. espeakPitchRangeTest( 10, 10, synth);
  395. espeakPitchRangeTest( -5, 0, synth); // clamped to minimum value
  396. }
  397. public void espeakVolumeTest(int prefValue, int settingValue, SpeechSynthesis synth)
  398. {
  399. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  400. SharedPreferences.Editor editor = prefs.edit();
  401. editor.clear();
  402. editor.putString("espeak_volume", Integer.toString(prefValue));
  403. editor.commit();
  404. VoiceSettings settings = new VoiceSettings(prefs, synth);
  405. assertThat(settings.getVoiceVariant().toString(), is("male"));
  406. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  407. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  408. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  409. assertThat(settings.getVolume(), is(settingValue));
  410. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  411. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  412. try {
  413. JSONObject json = settings.toJSON();
  414. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  415. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  416. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  417. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  418. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  419. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  420. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  421. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  422. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  423. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(settingValue));
  424. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  425. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  426. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  427. } catch (JSONException e) {
  428. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  429. }
  430. }
  431. public void testEspeakVolume()
  432. {
  433. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  434. espeakVolumeTest(210, 200, synth); // clamped to maximum value
  435. espeakVolumeTest(150, 150, synth);
  436. espeakVolumeTest(100, 100, synth); // default value
  437. espeakVolumeTest( 50, 50, synth);
  438. espeakVolumeTest( -5, 0, synth); // clamped to minimum value
  439. }
  440. public void espeakPunctuationLevelTest(int prefValue, int settingValue, String jsonValue, SpeechSynthesis synth)
  441. {
  442. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  443. SharedPreferences.Editor editor = prefs.edit();
  444. editor.clear();
  445. editor.putString("espeak_punctuation_level", Integer.toString(prefValue));
  446. editor.commit();
  447. VoiceSettings settings = new VoiceSettings(prefs, synth);
  448. assertThat(settings.getVoiceVariant().toString(), is("male"));
  449. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  450. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  451. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  452. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  453. assertThat(settings.getPunctuationLevel(), is(settingValue));
  454. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  455. try {
  456. JSONObject json = settings.toJSON();
  457. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  458. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  459. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  460. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  461. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  462. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  463. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  464. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  465. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  466. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  467. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  468. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(jsonValue));
  469. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  470. } catch (JSONException e) {
  471. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  472. }
  473. }
  474. public void testEspeakPunctuationLevel()
  475. {
  476. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  477. espeakPunctuationLevelTest( 3, SpeechSynthesis.PUNCT_SOME, "some", synth); // clamped to maximum value
  478. espeakPunctuationLevelTest( 2, SpeechSynthesis.PUNCT_SOME, "some", synth);
  479. espeakPunctuationLevelTest( 1, SpeechSynthesis.PUNCT_ALL, "all", synth);
  480. espeakPunctuationLevelTest( 0, SpeechSynthesis.PUNCT_NONE, "none", synth);
  481. espeakPunctuationLevelTest(-1, SpeechSynthesis.PUNCT_NONE, "none", synth); // clamped to minimum value
  482. }
  483. public void testEspeakPunctuationCharacters()
  484. {
  485. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  486. SharedPreferences.Editor editor = prefs.edit();
  487. editor.clear();
  488. editor.putString("espeak_punctuation_characters", ".?!");
  489. editor.commit();
  490. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  491. VoiceSettings settings = new VoiceSettings(prefs, synth);
  492. assertThat(settings.getVoiceVariant().toString(), is("male"));
  493. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  494. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  495. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  496. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  497. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  498. assertThat(settings.getPunctuationCharacters(), is(".?!"));
  499. try {
  500. JSONObject json = settings.toJSON();
  501. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  502. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  503. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  504. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  505. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  506. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  507. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  508. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  509. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  510. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  511. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  512. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  513. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(instanceOf(String.class)));
  514. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(".?!"));
  515. } catch (JSONException e) {
  516. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  517. }
  518. }
  519. // Mixed (Old and New) Settings
  520. public void testEspeakVariantWithDefaultGenderFemale()
  521. {
  522. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  523. SharedPreferences.Editor editor = prefs.edit();
  524. editor.clear();
  525. editor.putString("default_gender", Integer.toString(SpeechSynthesis.GENDER_FEMALE));
  526. editor.putString("espeak_variant", "klatt4");
  527. editor.commit();
  528. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  529. VoiceSettings settings = new VoiceSettings(prefs, synth);
  530. assertThat(settings.getVoiceVariant().toString(), is("klatt4"));
  531. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  532. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  533. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  534. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  535. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  536. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  537. try {
  538. JSONObject json = settings.toJSON();
  539. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  540. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("klatt4"));
  541. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  542. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  543. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  544. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  545. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  546. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  547. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  548. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  549. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  550. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  551. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  552. } catch (JSONException e) {
  553. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  554. }
  555. }
  556. public void testEspeakRateWithDefaultRate()
  557. {
  558. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  559. SharedPreferences.Editor editor = prefs.edit();
  560. editor.clear();
  561. editor.putString("default_rate", Integer.toString(50));
  562. editor.putString("espeak_rate", Integer.toString(200));
  563. editor.commit();
  564. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  565. VoiceSettings settings = new VoiceSettings(prefs, synth);
  566. assertThat(settings.getVoiceVariant().toString(), is("male"));
  567. assertThat(settings.getRate(), is(200));
  568. assertThat(settings.getPitch(), is(synth.Pitch.getDefaultValue()));
  569. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  570. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  571. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  572. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  573. try {
  574. JSONObject json = settings.toJSON();
  575. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  576. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  577. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  578. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(200));
  579. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  580. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(synth.Pitch.getDefaultValue()));
  581. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  582. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  583. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  584. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  585. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  586. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  587. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  588. } catch (JSONException e) {
  589. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  590. }
  591. }
  592. public void testEspeakPitchWithDefaultPitch()
  593. {
  594. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  595. SharedPreferences.Editor editor = prefs.edit();
  596. editor.clear();
  597. editor.putString("default_pitch", Integer.toString(50));
  598. editor.putString("espeak_pitch", Integer.toString(75));
  599. editor.commit();
  600. SpeechSynthesis synth = new SpeechSynthesis(getContext(), mCallback);
  601. VoiceSettings settings = new VoiceSettings(prefs, synth);
  602. assertThat(settings.getVoiceVariant().toString(), is("male"));
  603. assertThat(settings.getRate(), is(synth.Rate.getDefaultValue()));
  604. assertThat(settings.getPitch(), is(75));
  605. assertThat(settings.getPitchRange(), is(synth.PitchRange.getDefaultValue()));
  606. assertThat(settings.getVolume(), is(synth.Volume.getDefaultValue()));
  607. assertThat(settings.getPunctuationLevel(), is(SpeechSynthesis.PUNCT_NONE));
  608. assertThat(settings.getPunctuationCharacters(), is(nullValue()));
  609. try {
  610. JSONObject json = settings.toJSON();
  611. assertThat(json.opt(VoiceSettings.PRESET_VARIANT), is(instanceOf(String.class)));
  612. assertThat((String)json.opt(VoiceSettings.PRESET_VARIANT), is("male"));
  613. assertThat(json.opt(VoiceSettings.PRESET_RATE), is(instanceOf(Integer.class)));
  614. assertThat((Integer)json.opt(VoiceSettings.PRESET_RATE), is(synth.Rate.getDefaultValue()));
  615. assertThat(json.opt(VoiceSettings.PRESET_PITCH), is(instanceOf(Integer.class)));
  616. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH), is(75));
  617. assertThat(json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(instanceOf(Integer.class)));
  618. assertThat((Integer)json.opt(VoiceSettings.PRESET_PITCH_RANGE), is(synth.PitchRange.getDefaultValue()));
  619. assertThat(json.opt(VoiceSettings.PRESET_VOLUME), is(instanceOf(Integer.class)));
  620. assertThat((Integer)json.opt(VoiceSettings.PRESET_VOLUME), is(synth.Volume.getDefaultValue()));
  621. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is(instanceOf(String.class)));
  622. assertThat((String)json.opt(VoiceSettings.PRESET_PUNCTUATION_LEVEL), is("none"));
  623. assertThat(json.opt(VoiceSettings.PRESET_PUNCTUATION_CHARACTERS), is(nullValue()));
  624. } catch (JSONException e) {
  625. assertThat(e.toString(), is(nullValue())); // This will be false; used to report exception.
  626. }
  627. }
  628. }