diff --git a/Makefile.am b/Makefile.am index 11597b22..12c2c896 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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: diff --git a/android/res/raw/espeakdata.zip b/android/res/raw/espeakdata.zip index 0c02e70d..900e9d0c 100644 Binary files a/android/res/raw/espeakdata.zip and b/android/res/raw/espeakdata.zip differ diff --git a/android/res/raw/espeakdata_version b/android/res/raw/espeakdata_version new file mode 100644 index 00000000..da5b7354 --- /dev/null +++ b/android/res/raw/espeakdata_version @@ -0,0 +1 @@ +6e7a49d1894b9915873b8bc066f35c65e155c31e diff --git a/android/src/com/reecedunn/espeak/CheckVoiceData.java b/android/src/com/reecedunn/espeak/CheckVoiceData.java index 62e8ddaf..bdcb493e 100755 --- a/android/src/com/reecedunn/espeak/CheckVoiceData.java +++ b/android/src/com/reecedunn/espeak/CheckVoiceData.java @@ -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 availableLanguages = new ArrayList(); ArrayList unavailableLanguages = new ArrayList(); - if (!hasBaseResources(this)) { + if (!hasBaseResources(this) || canUpgradeResources(this)) { if (!attemptedInstall) { downloadVoiceData(); return; diff --git a/android/src/com/reecedunn/espeak/DownloadVoiceData.java b/android/src/com/reecedunn/espeak/DownloadVoiceData.java index d3c815a7..04bfe7e7 100755 --- a/android/src/com/reecedunn/espeak/DownloadVoiceData.java +++ b/android/src/com/reecedunn/espeak/DownloadVoiceData.java @@ -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() {