Skip to content

Commit

Permalink
Code style and comment fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikunimaru committed Jun 2, 2021
1 parent e814c49 commit 27ca6ff
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4207,31 +4207,31 @@ public boolean ankiIsActiveNetworkMetered() {
}

//Voice reading
JavaScriptTTS mTalker = new JavaScriptTTS (AbstractFlashcardViewer.this);
JavaScriptTTS mTalker = new JavaScriptTTS(AbstractFlashcardViewer.this);

@JavascriptInterface
public int ankiTtsSpeak(String text, int queueMode) {
return mTalker.speak(text, queueMode);
return mTalker.speak(text, queueMode);
}

@JavascriptInterface
public int ankiTtsSpeak(String text) {
return mTalker.speak(text);
return mTalker.speak(text);
}

@JavascriptInterface
public int ankiTtsSetLanguage(String loc) {
return mTalker.setLanguage(loc);
return mTalker.setLanguage(loc);
}

@JavascriptInterface
public int ankiTtsSetPitch(float pitch) {
return mTalker.setPitch(pitch);
return mTalker.setPitch(pitch);
}

@JavascriptInterface
public int ankiTtsSetPitch(double pitch) {
return mTalker.setPitch((float)pitch);
return mTalker.setPitch((float)pitch);
}

@JavascriptInterface
Expand Down
60 changes: 42 additions & 18 deletions AnkiDroid/src/main/java/com/ichi2/anki/JavaScriptTTS.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
import android.speech.tts.TextToSpeech;
import java.util.Locale;

// Since it is assumed that only advanced users will use the JavaScript api,
// here, Android's TextToSpeech is converted for JavaScript almost as it is, giving priority to free behavior.
// https://developer.android.com/reference/android/speech/tts/TextToSpeech
//
//

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

private TextToSpeech mTts;
private boolean mTtsOk;
private static final Bundle mTtsParams = new Bundle();

//The constructor will create a TextToSpeech instance.
JavaScriptTTS(Context context) {
mTts = new TextToSpeech(context, this);
}

@Override
//OnInitListener method to receive the TTS engine status
/** OnInitListener method to receive the TTS engine status */
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
mTtsOk = true;
Expand All @@ -32,42 +30,68 @@ public void onInit(int status) {
mTtsOk = false;
}
}

// A method to speak something
// The QueMode value is 1 for QUEUE_ADD and 0 for QUEUE_FLUSH.

/**
* A method to speak something
* @param text Content to speak
* @param queueMode 1 for QUEUE_ADD and 0 for QUEUE_FLUSH.
* @return ERROR(-1) SUCCESS(0)
*/
public int speak(String text, int queueMode) {
return mTts.speak(text, queueMode, mTtsParams, "stringId");
}

// If only a string is given, set QUEUE_FLUSH to the default behavior.
/**
* If only a string is given, set QUEUE_FLUSH to the default behavior.
* @param text Content to speak
* @return ERROR(-1) SUCCESS(0)
*/
public int speak(String text) {
return mTts.speak(text, TextToSpeech.QUEUE_FLUSH, mTtsParams, "stringId");
}

// Sets the text-to-speech language.
//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.
/**
* Sets the text-to-speech language.
* 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.
* @param loc Specifying the language to speak
* @return 0 Denotes the language is available for the language by the locale, but not the country and variant.
* <li> 1 Denotes the language is available for the language and country specified by the locale, but not the variant.
* <li> 2 Denotes the language is available exactly as specified by the locale.
* <li> -1 Denotes the language data is missing.
* <li> -2 Denotes the language is not supported.
*/
public int setLanguage(String loc) {
// The Int values will be returned
// 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.
return mTts.setLanguage(localeFromStringIgnoringScriptAndExtensions(loc));
}

// Sets the speech pitch for the TextToSpeech engine. This has no effect on any pre-recorded speech.
// float: Speech pitch. 1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it.

/**
* Sets the speech pitch for the TextToSpeech engine. This has no effect on any pre-recorded speech.
* @param pitch float: Speech pitch. 1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it.
* @return ERROR(-1) SUCCESS(0)
*/
public int setPitch(float pitch) {
// The following Int values will be returned
// ERROR(-1) SUCCESS(0)
return mTts.setPitch(pitch);
}

// Sets the speech rate. This has no effect on any pre-recorded speech.
/**
*
* @param speechRate Sets the speech rate. 1.0 is the normal speech rate. This has no effect on any pre-recorded speech.
* @return ERROR(-1) SUCCESS(0)
*/
public int setSpeechRate(float speechRate) {
// The following Int values will be returned
// ERROR(-1) SUCCESS(0)
return mTts.setSpeechRate(speechRate);
}

// Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue.
/**
* Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue.
*/
public void stop() {
// The following Int values will be returned
// ERROR(-1) SUCCESS(0)
Expand Down

0 comments on commit 27ca6ff

Please sign in to comment.