Skip to content

Commit

Permalink
Fixing gradle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihir Soni committed Nov 7, 2015
1 parent c274d96 commit 9fc55c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 21
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/mihir/react/tts/RCTTextToSpeech.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mihir.react.tts;


import android.annotation.TargetApi;
import android.os.Build;
import android.speech.tts.TextToSpeech;


import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
Expand All @@ -24,6 +27,7 @@
public class RCTTextToSpeech extends ReactContextBaseJavaModule{

private static TextToSpeech tts;
private int MY_DATA_CHECK_CODE = 0;

public RCTTextToSpeech(ReactApplicationContext reactContext) {
super(reactContext);
Expand All @@ -35,18 +39,20 @@ public RCTTextToSpeech(ReactApplicationContext reactContext) {
*/
@ReactMethod
public void getLocale(final Callback callback) {
FLog.i(ReactConstants.TAG, "Got the locales now trying to return ");
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
try{
if(tts == null){
init();
}
Set<Locale> availableLanguages = tts.getAvailableLanguages();
Locale[] locales = Locale.getAvailableLocales();
WritableArray data = Arguments.createArray();
for (Locale locale : availableLanguages) {
data.pushString(locale.getDisplayLanguage());
for (Locale locale : locales) {
int res = tts.isLanguageAvailable(locale);
if(res == TextToSpeech.LANG_COUNTRY_AVAILABLE){
data.pushString(locale.getLanguage());
}
}
callback.invoke(null,data);
} catch (Exception e) {
Expand Down Expand Up @@ -132,6 +138,7 @@ protected void doInBackgroundGuarded(Void... params) {
String language = args.hasKey("language") ? args.getString("language") : null;
Boolean forceStop = args.hasKey("forceStop") ? args.getBoolean("forceStop") : null;
Float pitch = args.hasKey("pitch") ? (float) args.getDouble("pitch") : null;

if(tts.isSpeaking()){
//Force to stop and start new speech
if(forceStop != null && forceStop){
Expand All @@ -155,7 +162,11 @@ protected void doInBackgroundGuarded(Void... params) {
if(pitch != null){
tts.setPitch(pitch);
}
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null,null);
//TODO:: Need to implement the UTTERANCE Id and give the callback
if(Build.VERSION.SDK_INT >= 21)
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null,null);
else
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
callback.invoke(true);
} catch (Exception e) {
callback.invoke(false);
Expand Down

0 comments on commit 9fc55c9

Please sign in to comment.