Browse Source

Support installing the voices if the voice data signature has changed.

master
Reece H. Dunn 12 years ago
parent
commit
9f2293221d

+ 4
- 1
Makefile.am View File

@@ -132,7 +132,10 @@ android/res/raw/espeakdata.zip: espeak-data/dir.stamp espeak-data/phontab dictio
espeak-data/phondata espeak-data/phonindex espeak-data/phontab \
espeak-data/*_dict espeak-data/voices

android: android/res/raw/espeakdata.zip
android/res/raw/espeakdata_version: android/res/raw/espeakdata.zip
sha1sum $< | awk '{ print $$1 }' > $@

android: android/res/raw/espeakdata.zip android/res/raw/espeakdata_version

##### dictionaries:


BIN
android/res/raw/espeakdata.zip View File


+ 1
- 0
android/res/raw/espeakdata_version View File

@@ -0,0 +1 @@
6e7a49d1894b9915873b8bc066f35c65e155c31e

+ 35
- 2
android/src/com/reecedunn/espeak/CheckVoiceData.java View File

@@ -1,4 +1,5 @@
/*
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +26,7 @@ package com.reecedunn.espeak;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.Engine;
@@ -33,7 +35,11 @@ import android.util.Log;
import com.reecedunn.espeak.SpeechSynthesis.SynthReadyCallback;
import com.reecedunn.espeak.SpeechSynthesis.Voice;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -47,7 +53,13 @@ public class CheckVoiceData extends Activity {

/** Resources required for eSpeak to run correctly. */
private static final String[] BASE_RESOURCES = {
"intonations", "phondata", "phonindex", "phontab", "en_dict", "voices/en/en-us"
"version",
"intonations",
"phondata",
"phonindex",
"phontab",
"en_dict",
"voices/en/en-us"
};

public static File getDataPath(Context context) {
@@ -69,6 +81,27 @@ public class CheckVoiceData extends Activity {
return true;
}

public static String readContent(InputStream stream) throws IOException {
ByteArrayOutputStream content = new ByteArrayOutputStream();
int c = stream.read();
while (c != -1)
{
content.write((byte)c);
c = stream.read();
}
return content.toString();
}

public static boolean canUpgradeResources(Context context) {
try {
final String version = readContent(context.getResources().openRawResource(R.raw.espeakdata_version));
final String installedVersion = readContent(new FileInputStream(new File(getDataPath(context), "version")));
return !version.equals(installedVersion);
} catch (Exception e) {
return false;
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -91,7 +124,7 @@ public class CheckVoiceData extends Activity {
ArrayList<String> availableLanguages = new ArrayList<String>();
ArrayList<String> unavailableLanguages = new ArrayList<String>();

if (!hasBaseResources(this)) {
if (!hasBaseResources(this) || canUpgradeResources(this)) {
if (!attemptedInstall) {
downloadVoiceData();
return;

+ 9
- 0
android/src/com/reecedunn/espeak/DownloadVoiceData.java View File

@@ -173,6 +173,15 @@ public class DownloadVoiceData extends Activity {
// Make sure the output file is readable.
doChmod(outputFile);
}

final String version = CheckVoiceData.readContent(mContext.getResources().openRawResource(R.raw.espeakdata_version));
final File outputFile = new File(mOutput, "espeak-data/version");
mExtractedFiles.add(outputFile);

final FileOutputStream outputStream = new FileOutputStream(outputFile);
outputStream.write(version.getBytes(), 0, version.length());
outputStream.close();
doChmod(outputFile);
}

private void removeExtractedFiles() {

Loading…
Cancel
Save