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

espeak-data/phondata espeak-data/phonindex espeak-data/phontab \ espeak-data/phondata espeak-data/phonindex espeak-data/phontab \
espeak-data/*_dict espeak-data/voices 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: ##### dictionaries:



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


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

6e7a49d1894b9915873b8bc066f35c65e155c31e

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

/* /*
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2009 The Android Open Source Project * Copyright (C) 2009 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle; import android.os.Bundle;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.Engine; import android.speech.tts.TextToSpeech.Engine;
import com.reecedunn.espeak.SpeechSynthesis.SynthReadyCallback; import com.reecedunn.espeak.SpeechSynthesis.SynthReadyCallback;
import com.reecedunn.espeak.SpeechSynthesis.Voice; import com.reecedunn.espeak.SpeechSynthesis.Voice;


import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;


/** Resources required for eSpeak to run correctly. */ /** Resources required for eSpeak to run correctly. */
private static final String[] BASE_RESOURCES = { 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) { public static File getDataPath(Context context) {
return true; 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 @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ArrayList<String> availableLanguages = new ArrayList<String>(); ArrayList<String> availableLanguages = new ArrayList<String>();
ArrayList<String> unavailableLanguages = new ArrayList<String>(); ArrayList<String> unavailableLanguages = new ArrayList<String>();


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

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

// Make sure the output file is readable. // Make sure the output file is readable.
doChmod(outputFile); 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() { private void removeExtractedFiles() {

Loading…
Cancel
Save