Skip to content

Commit d9023e2

Browse files
committed
Code style and comment fixes
1 parent bc0713b commit d9023e2

2 files changed

Lines changed: 48 additions & 24 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4214,31 +4214,31 @@ public boolean ankiIsActiveNetworkMetered() {
42144214
}
42154215

42164216
//Voice reading
4217-
JavaScriptTTS mTalker = new JavaScriptTTS (AbstractFlashcardViewer.this);
4217+
JavaScriptTTS mTalker = new JavaScriptTTS(AbstractFlashcardViewer.this);
42184218

42194219
@JavascriptInterface
42204220
public int ankiTtsSpeak(String text, int queueMode) {
4221-
return mTalker.speak(text, queueMode);
4221+
return mTalker.speak(text, queueMode);
42224222
}
42234223

42244224
@JavascriptInterface
42254225
public int ankiTtsSpeak(String text) {
4226-
return mTalker.speak(text);
4226+
return mTalker.speak(text);
42274227
}
42284228

42294229
@JavascriptInterface
42304230
public int ankiTtsSetLanguage(String loc) {
4231-
return mTalker.setLanguage(loc);
4231+
return mTalker.setLanguage(loc);
42324232
}
42334233

42344234
@JavascriptInterface
42354235
public int ankiTtsSetPitch(float pitch) {
4236-
return mTalker.setPitch(pitch);
4236+
return mTalker.setPitch(pitch);
42374237
}
42384238

42394239
@JavascriptInterface
42404240
public int ankiTtsSetPitch(double pitch) {
4241-
return mTalker.setPitch((float)pitch);
4241+
return mTalker.setPitch((float)pitch);
42424242
}
42434243

42444244
@JavascriptInterface

AnkiDroid/src/main/java/com/ichi2/anki/JavaScriptTTS.java

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@
55
import android.speech.tts.TextToSpeech;
66
import java.util.Locale;
77

8-
// Since it is assumed that only advanced users will use the JavaScript api,
9-
// here, Android's TextToSpeech is converted for JavaScript almost as it is, giving priority to free behavior.
10-
// https://developer.android.com/reference/android/speech/tts/TextToSpeech
11-
//
12-
//
13-
8+
/**
9+
* Since it is assumed that only advanced users will use the JavaScript api,
10+
* here, Android's TextToSpeech is converted for JavaScript almost as it is, giving priority to free behavior.
11+
* https://developer.android.com/reference/android/speech/tts/TextToSpeech
12+
*/
1413
public class JavaScriptTTS implements TextToSpeech.OnInitListener {
1514

1615
private TextToSpeech mTts;
1716
private boolean mTtsOk;
1817
private static final Bundle mTtsParams = new Bundle();
1918

20-
//The constructor will create a TextToSpeech instance.
2119
JavaScriptTTS(Context context) {
2220
mTts = new TextToSpeech(context, this);
2321
}
2422

2523
@Override
26-
//OnInitListener method to receive the TTS engine status
24+
/** OnInitListener method to receive the TTS engine status */
2725
public void onInit(int status) {
2826
if (status == TextToSpeech.SUCCESS) {
2927
mTtsOk = true;
@@ -32,42 +30,68 @@ public void onInit(int status) {
3230
mTtsOk = false;
3331
}
3432
}
35-
36-
// A method to speak something
37-
// The QueMode value is 1 for QUEUE_ADD and 0 for QUEUE_FLUSH.
33+
34+
/**
35+
* A method to speak something
36+
* @param text Content to speak
37+
* @param queueMode 1 for QUEUE_ADD and 0 for QUEUE_FLUSH.
38+
* @return ERROR(-1) SUCCESS(0)
39+
*/
3840
public int speak(String text, int queueMode) {
3941
return mTts.speak(text, queueMode, mTtsParams, "stringId");
4042
}
4143

42-
// If only a string is given, set QUEUE_FLUSH to the default behavior.
44+
/**
45+
* If only a string is given, set QUEUE_FLUSH to the default behavior.
46+
* @param text Content to speak
47+
* @return ERROR(-1) SUCCESS(0)
48+
*/
4349
public int speak(String text) {
4450
return mTts.speak(text, TextToSpeech.QUEUE_FLUSH, mTtsParams, "stringId");
4551
}
4652

47-
// Sets the text-to-speech language.
48-
//The TTS engine will try to use the closest match to the specified language as represented by the Locale, but there is no guarantee that the exact same Locale will be used.
53+
/**
54+
* Sets the text-to-speech language.
55+
* The TTS engine will try to use the closest match to the specified language as represented by the Locale, but there is no guarantee that the exact same Locale will be used.
56+
* @param loc Specifying the language to speak
57+
* @return 0 Denotes the language is available for the language by the locale, but not the country and variant.
58+
* <li> 1 Denotes the language is available for the language and country specified by the locale, but not the variant.
59+
* <li> 2 Denotes the language is available exactly as specified by the locale.
60+
* <li> -1 Denotes the language data is missing.
61+
* <li> -2 Denotes the language is not supported.
62+
*/
4963
public int setLanguage(String loc) {
5064
// The Int values will be returned
5165
// Code indicating the support status for the locale. See LANG_AVAILABLE, LANG_COUNTRY_AVAILABLE, LANG_COUNTRY_VAR_AVAILABLE, LANG_MISSING_DATA and LANG_NOT_SUPPORTED.
5266
return mTts.setLanguage(localeFromStringIgnoringScriptAndExtensions(loc));
5367
}
5468

55-
// Sets the speech pitch for the TextToSpeech engine. This has no effect on any pre-recorded speech.
56-
// float: Speech pitch. 1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it.
69+
70+
/**
71+
* Sets the speech pitch for the TextToSpeech engine. This has no effect on any pre-recorded speech.
72+
* @param pitch float: Speech pitch. 1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it.
73+
* @return ERROR(-1) SUCCESS(0)
74+
*/
5775
public int setPitch(float pitch) {
5876
// The following Int values will be returned
5977
// ERROR(-1) SUCCESS(0)
6078
return mTts.setPitch(pitch);
6179
}
6280

63-
// Sets the speech rate. This has no effect on any pre-recorded speech.
81+
/**
82+
*
83+
* @param speechRate Sets the speech rate. 1.0 is the normal speech rate. This has no effect on any pre-recorded speech.
84+
* @return ERROR(-1) SUCCESS(0)
85+
*/
6486
public int setSpeechRate(float speechRate) {
6587
// The following Int values will be returned
6688
// ERROR(-1) SUCCESS(0)
6789
return mTts.setSpeechRate(speechRate);
6890
}
6991

70-
// Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue.
92+
/**
93+
* Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue.
94+
*/
7195
public void stop() {
7296
// The following Int values will be returned
7397
// ERROR(-1) SUCCESS(0)

0 commit comments

Comments
 (0)