Browse Source

Fix updating the number of installed voices after installing them within the activity.

master
Reece H. Dunn 11 years ago
parent
commit
8f82baa646

+ 6
- 0
android/src/com/reecedunn/espeak/SpeechSynthesis.java View File

@@ -60,6 +60,7 @@ public class SpeechSynthesis {
private final String mDatapath;

private boolean mInitialized = false;
private static int mVoiceCount = 0;

public SpeechSynthesis(Context context, SynthReadyCallback callback) {
// First, ensure the data directory exists, otherwise init will crash.
@@ -86,6 +87,10 @@ public class SpeechSynthesis {
return nativeGetVersion();
}

public static int getVoiceCount() {
return mVoiceCount;
}

public int getSampleRate() {
return nativeGetSampleRate();
}
@@ -107,6 +112,7 @@ public class SpeechSynthesis {
public List<Voice> getAvailableVoices() {
final List<Voice> voices = new LinkedList<Voice>();
final String[] results = nativeGetAvailableVoices();
mVoiceCount = results.length / 4;

for (int i = 0; i < results.length; i += 4) {
final String name = results[i];

+ 5
- 0
android/src/com/reecedunn/espeak/TtsService.java View File

@@ -51,6 +51,8 @@ import java.util.Locale;
*/
@SuppressLint("NewApi")
public class TtsService extends TextToSpeechService {
public static final String ESPEAK_INITIALIZED = "com.reecedunn.espeak.ESPEAK_INITIALIZED";

private static final String TAG = TtsService.class.getSimpleName();
private static final boolean DEBUG = false;

@@ -95,6 +97,9 @@ public class TtsService extends TextToSpeechService {

mEngine = new SpeechSynthesis(this, mSynthCallback);
mAvailableVoices = mEngine.getAvailableVoices();

final Intent intent = new Intent(ESPEAK_INITIALIZED);
sendBroadcast(intent);
}

@Override

+ 16
- 9
android/src/com/reecedunn/espeak/eSpeakActivity.java View File

@@ -18,7 +18,10 @@
package com.reecedunn.espeak;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -58,12 +61,18 @@ public class eSpeakActivity extends Activity {
}

private State mState;
private ArrayList<String> mVoices;
private TextToSpeech mTts;
private List<Pair<String,String>> mInformation;
private InformationListAdapter mInformationView;
private EditText mText;

private final BroadcastReceiver mOnEspeakInitialized = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
populateInformationView();
}
};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -75,6 +84,9 @@ public class eSpeakActivity extends Activity {
((ListView)findViewById(R.id.properties)).setAdapter(mInformationView);
mText = (EditText)findViewById(R.id.editText1);

final IntentFilter filter = new IntentFilter(TtsService.ESPEAK_INITIALIZED);
registerReceiver(mOnEspeakInitialized, filter);

setState(State.LOADING);
checkVoiceData();

@@ -102,6 +114,8 @@ public class eSpeakActivity extends Activity {
public void onStop() {
super.onStop();

unregisterReceiver(mOnEspeakInitialized);

if (mTts != null) {
mTts.shutdown();
}
@@ -182,11 +196,7 @@ public class eSpeakActivity extends Activity {
}

final String availableVoices = getString(R.string.available_voices);
if (mVoices == null) {
mInformation.add(new Pair<String,String>(availableVoices, "0"));
} else {
mInformation.add(new Pair<String,String>(availableVoices, Integer.toString(mVoices.size())));
}
mInformation.add(new Pair<String,String>(availableVoices, Integer.toString(SpeechSynthesis.getVoiceCount())));

final String version = getString(R.string.tts_version);
mInformation.add(new Pair<String,String>(version, SpeechSynthesis.getVersion()));
@@ -227,12 +237,9 @@ public class eSpeakActivity extends Activity {
if (resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
Log.e(TAG, "Voice data check failed (error code: " + resultCode + ").");
setState(State.ERROR);
} else {
mVoices = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
}

initializeEngine();
populateInformationView();
}

/**

Loading…
Cancel
Save