Attempt to add ability to download js tts

This commit is contained in:
PaulStets 2018-08-03 16:44:51 +03:00
parent 653d12b225
commit c2153c8c28
18 changed files with 127 additions and 42 deletions

View file

@ -34,7 +34,8 @@ public class IndexConstants {
public static final String GEN_LOG_EXT = ".gen.log"; //$NON-NLS-1$
public static final String VOICE_INDEX_EXT_ZIP = ".voice.zip"; //$NON-NLS-1$
public static final String TTSVOICE_INDEX_EXT_ZIP = ".ttsvoice.zip"; //$NON-NLS-1$
public static final String TTSVOICE_INDEX_EXT_ZIP = ".ttsvoice.zip";
public static final String TTSVOICE_INDEX_EXT_JS = "tts.js";
public static final String ANYVOICE_INDEX_EXT_ZIP = "voice.zip"; //$NON-NLS-1$ //to cactch both voices, .voice.zip and .ttsvoice.zip
public static final String FONT_INDEX_EXT = ".otf"; //$NON-NLS-1$
@ -67,9 +68,4 @@ public class IndexConstants {
public static final String VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$
public static final String RENDERERS_DIR = "rendering/"; //$NON-NLS-1$
public static final String ROUTING_XML_FILE= "routing.xml";
}

View file

@ -43,6 +43,45 @@
<asset source="voice/zh/ttsconfig.p" destination="voice/zh-tts/_ttsconfig.p" mode="alwaysOverwriteOrCopy" />
<asset source="voice/zh-hk/ttsconfig.p" destination="voice/zh-hk-tts/_ttsconfig.p" mode="overwriteOnlyIfExists" />
<!--JavaScript files-->
<!--<asset source="voice/ar/ar_tts.js" destination="voice/ar-tts/ar_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/be/be_tts.js" destination="voice/be-tts/be_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/cs/cs_tts.js" destination="voice/cs-tts/cs_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/da/da_tts.js" destination="voice/da-tts/da_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/de/de_tts.js" destination="voice/de-tts/de_tts.js" mode="alwaysOverwriteOrCopy" />
<!--<asset source="voice/el/el_tts.js" destination="voice/el-tts/el_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/en/en_tts.js" destination="voice/en-tts/en_tts.js" mode="alwaysOverwriteOrCopy" />
<!--<asset source="voice/en-gb/en-gb_tts.js" destination="voice/en-gb-tts/en-gb_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/es/es_tts.js" destination="voice/es-tts/es_tts.js" mode="alwaysOverwriteOrCopy" />
<!--<asset source="voice/es-ar/es-ar_tts.js" destination="voice/es-ar-tts/es-ar_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/et/et_tts.js" destination="voice/et-tts/et_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/fa/fa_tts.js" destination="voice/fa-tts/fa_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/fi/fi_tts.js" destination="voice/fi-tts/fi_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/fr/fr_tts.js" destination="voice/fr-tts/fr_tts.js" mode="alwaysOverwriteOrCopy" />
<!--<asset source="voice/he/he_tts.js" destination="voice/he-tts/he_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/hi/hi_tts.js" destination="voice/hi-tts/hi_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/hr/hr_tts.js" destination="voice/hr-tts/hr_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/hu/hu_tts.js" destination="voice/hu-tts/hu_tts.js" mode="overwriteOnlyIfExists" />
<!--<asset source="voice/hu-formal/hu-formal_tts.js" destination="voice/hu_formal-tts/hu-formal_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/it/it_tts.js" destination="voice/it-tts/it_tts.js" mode="alwaysOverwriteOrCopy" />
<!--<asset source="voice/ja/ja_tts.js" destination="voice/ja-tts/ja_tts.js" mode="alwaysOverwriteOrCopy" />-->
<!--<asset source="voice/ko/ko_tts.js" destination="voice/ko-tts/ko_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/lv/lv_tts.js" destination="voice/lv-tts/lv_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/nl/nl_tts.js" destination="voice/nl-tts/nl_tts.js" mode="alwaysOverwriteOrCopy" />
<asset source="voice/pl/pl_tts.js" destination="voice/pl-tts/pl_tts.js" mode="alwaysOverwriteOrCopy" />
<asset source="voice/pt/pt_tts.js" destination="voice/pt-tts/pt_tts.js" mode="alwaysOverwriteOrCopy" />
<!--<asset source="voice/pt-br/pt-br_tts.js" destination="voice/pt-br-tts/pt-br_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/ro/ro_tts.js" destination="voice/ro-tts/ro_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/ru/ru_tts.js" destination="voice/ru-tts/ru_tts.js" mode="alwaysOverwriteOrCopy" />
<!--<asset source="voice/sc/sc_tts.js" destination="voice/sc-tts/sc_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/sk/sk_tts.js" destination="voice/sk-tts/sk_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/sl/sl_tts.js" destination="voice/sl-tts/sl_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/sv/sv_tts.js" destination="voice/sv-tts/sv_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/sw/sw_tts.js" destination="voice/sw-tts/sw_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/uk/uk_tts.js" destination="voice/uk-tts/uk_tts.js" mode="overwriteOnlyIfExists" />-->
<!--<asset source="voice/zh/zh_tts.js" destination="voice/zh-tts/zh_tts.js" mode="alwaysOverwriteOrCopy" />-->
<!--<asset source="voice/zh-hk/zh-hk_tts.js" destination="voice/zh-hk-tts/zh-hk_tts.js" mode="overwriteOnlyIfExists" />-->
<asset source="voice/de/config.p" destination="voice/de/_config.p" mode="overwriteOnlyIfExists" />
<asset source="voice/en/config.p" destination="voice/en/_config.p" mode="overwriteOnlyIfExists" />
<asset source="voice/es/config.p" destination="voice/es/_config.p" mode="overwriteOnlyIfExists" />

View file

@ -238,6 +238,7 @@ task collectVoiceAssets(type: Sync) {
from "../../resources/voice"
into "assets/voice"
include "**/*.p"
include "**/*.js"
}
task cleanNoTranslate(type: Delete) {

View file

@ -2934,4 +2934,5 @@
<string name="use_js_voice_guidance">Use JS voice guidance</string>
<string name="use_js_voice_guidance_description">Use new voice guidance logic based on JavaScript</string>
<string name="test_voice_desrc">Tap a button and listen to the corresponding voice prompt to identify missing or faulty propmts.</string>
<string name="voice_tts_js">Voice prompts (JavaScript TTS)</string>
</resources>

View file

@ -13,6 +13,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.voice.JSTTSCommandPlayerImpl;
import net.osmand.plus.voice.MediaCommandPlayerImpl;
import net.osmand.plus.voice.TTSCommandPlayerImpl;
import net.osmand.util.Algorithms;
@ -87,6 +88,8 @@ public class LocalIndexHelper {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.TTS_VOICE_DATA_JS) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.DEACTIVATED) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.VOICE_DATA) {
@ -216,11 +219,12 @@ public class LocalIndexHelper {
private void loadVoiceData(File voiceDir, List<LocalIndexInfo> result, boolean backup, AbstractLoadLocalIndexTask loadTask) {
if (voiceDir.canRead()) {
//First list TTS files, they are preferred
boolean useJs = app.getSettings().USE_JS_VOICE_GUIDANCE.get();
for (File voiceF : listFilesSorted(voiceDir)) {
if (voiceF.isDirectory() && !MediaCommandPlayerImpl.isMyData(voiceF) && (Build.VERSION.SDK_INT >= 4)) {
if (voiceF.isDirectory() && !MediaCommandPlayerImpl.isMyData(voiceF)) {
LocalIndexInfo info = null;
if (TTSCommandPlayerImpl.isMyData(voiceF)) {
info = new LocalIndexInfo(LocalIndexType.TTS_VOICE_DATA, voiceF, backup, app);
if (useJs ? JSTTSCommandPlayerImpl.isMyData(voiceF) : TTSCommandPlayerImpl.isMyData(voiceF)) {
info = new LocalIndexInfo(useJs ? LocalIndexType.TTS_VOICE_DATA_JS : LocalIndexType.TTS_VOICE_DATA, voiceF, backup, app);
}
if (info != null) {
updateDescription(info);
@ -359,6 +363,7 @@ public class LocalIndexHelper {
WIKI_DATA(R.string.local_indexes_cat_wiki, R.drawable.ic_plugin_wikipedia, 50),
TRAVEL_DATA(R.string.download_maps_travel, R.drawable.ic_plugin_wikipedia, 60),
TTS_VOICE_DATA(R.string.local_indexes_cat_tts, R.drawable.ic_action_volume_up, 20),
TTS_VOICE_DATA_JS(R.string.voice_tts_js, R.drawable.ic_action_volume_up, 20),
VOICE_DATA(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up, 30),
FONT_DATA(R.string.fonts_header, R.drawable.ic_action_map_language, 35),
DEACTIVATED(R.string.local_indexes_cat_backup, R.drawable.ic_type_archive, 1000);

View file

@ -298,6 +298,8 @@ public class DownloadActivityType {
return FileNameTranslationHelper.getVoiceName(ctx, getBasename(indexItem));
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
return FileNameTranslationHelper.getVoiceName(ctx, getBasename(indexItem));
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) {
return FileNameTranslationHelper.getVoiceName(ctx, getBasename(indexItem));
}
return getBasename(indexItem);
}

View file

@ -165,6 +165,13 @@ public class DownloadOsmandIndexesHelper {
result.add(new AssetIndexItem(voice + ext, "voice", date, dateModified, "0.1", destFile.length(), key,
destFile.getPath(), DownloadActivityType.VOICE_FILE));
} else if (target.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS) && target.startsWith("voice/")) {
String lang = target.substring("voice/".length(), target.indexOf("-"));
File destFile = new File(voicePath, target.substring("voice/".length(),
target.indexOf("/", "voice/".length())) + "/" + lang + "_tts.js");
result.add(new AssetIndexItem(lang + "_" + IndexConstants.TTSVOICE_INDEX_EXT_JS,
"voice", date, dateModified, "0.1", destFile.length(), key,
destFile.getPath(), DownloadActivityType.VOICE_FILE));
}
}
result.sort();

View file

@ -39,6 +39,7 @@ public class DownloadResourceGroup {
NAUTICAL_MAPS_HEADER(R.string.nautical_maps),
// headers with voice items
VOICE_HEADER_TTS(R.string.index_name_tts_voice),
VOICE_HEADER_TTS_JS(R.string.voice_tts_js),
VOICE_HEADER_REC(R.string.index_name_voice),
// headers with font items
FONTS_HEADER(R.string.fonts_header),
@ -52,6 +53,7 @@ public class DownloadResourceGroup {
NAUTICAL_MAPS(R.string.nautical_maps),
WIKIVOYAGE_MAPS(R.string.download_maps_travel),
VOICE_TTS(R.string.index_name_tts_voice),
VOICE_TTS_JS(R.string.voice_tts_js),
FONTS(R.string.fonts_header),
VOICE_REC(R.string.index_name_voice),
OTHER_MAPS(R.string.download_select_map_types),
@ -65,7 +67,7 @@ public class DownloadResourceGroup {
}
public boolean isScreen() {
return this == WORLD || this == REGION || this == VOICE_TTS
return this == WORLD || this == REGION || this == VOICE_TTS || this == VOICE_TTS_JS
|| this == VOICE_REC || this == OTHER_MAPS || this == FONTS || this == NAUTICAL_MAPS || this == WIKIVOYAGE_MAPS;
}
@ -83,7 +85,8 @@ public class DownloadResourceGroup {
}
public boolean isHeader() {
return this == VOICE_HEADER_REC || this == VOICE_HEADER_TTS || this == SUBREGIONS
return this == VOICE_HEADER_REC || this == VOICE_HEADER_TTS || this == VOICE_HEADER_TTS_JS
|| this == SUBREGIONS
|| this == WORLD_MAPS || this == REGION_MAPS || this == OTHER_GROUP
|| this == HILLSHADE_HEADER || this == SRTM_HEADER
|| this == OTHER_MAPS_HEADER || this == OTHER_MAPS_GROUP

View file

@ -299,8 +299,10 @@ public class DownloadResources extends DownloadResourceGroup {
DownloadResourceGroup otherGroup = new DownloadResourceGroup(this, DownloadResourceGroupType.OTHER_GROUP);
DownloadResourceGroup voiceScreenTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_TTS);
DownloadResourceGroup voiceScreenRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_REC);
DownloadResourceGroup voiceScreenTTSJS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_TTS_JS);
DownloadResourceGroup fontScreen = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS);
DownloadResourceGroup voiceTTS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_TTS);
DownloadResourceGroup voiceTTSJS = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_TTS_JS);
DownloadResourceGroup voiceRec = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.VOICE_HEADER_REC);
DownloadResourceGroup fonts = new DownloadResourceGroup(otherGroup, DownloadResourceGroupType.FONTS_HEADER);
@ -320,6 +322,8 @@ public class DownloadResources extends DownloadResourceGroup {
if (ii.getType() == DownloadActivityType.VOICE_FILE) {
if (ii.getFileName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
voiceTTS.addItem(ii);
} else if (ii.getFileName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)){
voiceTTSJS.addItem(ii);
} else {
voiceRec.addItem(ii);
}
@ -414,12 +418,14 @@ public class DownloadResources extends DownloadResourceGroup {
}
voiceScreenTTS.addGroup(voiceTTS);
voiceScreenTTSJS.addGroup(voiceTTSJS);
voiceScreenRec.addGroup(voiceRec);
if (fonts.getIndividualResources() != null) {
fontScreen.addGroup(fonts);
}
otherGroup.addGroup(voiceScreenTTS);
otherGroup.addGroup(voiceScreenRec);
otherGroup.addGroup(voiceScreenTTSJS);
if (fonts.getIndividualResources() != null) {

View file

@ -28,7 +28,8 @@ public class DownloadGroupViewHolder {
private Drawable getIconForGroup(DownloadResourceGroup group) {
Drawable iconLeft;
if (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_REC
|| group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_TTS) {
|| group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_TTS
|| group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_TTS_JS) {
iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_volume_up);
} else if (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.FONTS) {
iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_map_language);

View file

@ -531,7 +531,8 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow
private Drawable getIconForGroup(DownloadResourceGroup group) {
Drawable iconLeft;
if (group.getType() == DownloadResourceGroupType.VOICE_REC
|| group.getType() == DownloadResourceGroupType.VOICE_TTS) {
|| group.getType() == DownloadResourceGroupType.VOICE_TTS || group.getType() ==
DownloadResourceGroupType.VOICE_TTS_JS) {
iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_volume_up);
} else if (group.getType() == DownloadResourceGroupType.FONTS) {
iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_map_language);

View file

@ -19,6 +19,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.IndexConstants;
import net.osmand.map.WorldRegion;
import net.osmand.plus.R;
import net.osmand.plus.Version;
@ -402,7 +403,8 @@ public class ItemViewHolder {
} else if (indexItem.getType() == DownloadActivityType.FONT_FILE) {
tp = LocalIndexType.FONT_DATA;
} else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
tp = indexItem.getBasename().contains("tts") ? LocalIndexType.TTS_VOICE_DATA
tp = indexItem.getFileName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS) ? LocalIndexType.TTS_VOICE_DATA_JS :
indexItem.getBasename().contains("tts") ? LocalIndexType.TTS_VOICE_DATA
: LocalIndexType.VOICE_DATA;
}
final LocalIndexInfo info = new LocalIndexInfo(tp, fl, false, context.getMyApplication());

View file

@ -200,7 +200,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
.setPosition(2).createItem());
}
if (info.getType() != LocalIndexType.TTS_VOICE_DATA && info.getType() != LocalIndexType.VOICE_DATA
&& info.getType() != LocalIndexType.FONT_DATA) {
&& info.getType() != LocalIndexType.FONT_DATA && info.getType() != LocalIndexType.TTS_VOICE_DATA_JS) {
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.shared_string_rename, getContext())
.setListener(listener)
@ -452,6 +452,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA_JS) {
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.FONT_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.FONT_INDEX_DIR);
}

View file

@ -492,6 +492,7 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
if (group.getType() == DownloadResourceGroupType.OTHER_MAPS_HEADER
|| group.getType() == DownloadResourceGroupType.VOICE_HEADER_REC
|| group.getType() == DownloadResourceGroupType.VOICE_HEADER_TTS
|| group.getType() == DownloadResourceGroupType.VOICE_HEADER_TTS_JS
|| group.getType() == DownloadResourceGroupType.FONTS_HEADER) {
if (group.getIndividualResources() != null) {
for (IndexItem item : group.getIndividualResources()) {

View file

@ -525,7 +525,8 @@ public class MapDataMenuController extends MenuController {
} else if (localIndexInfo.getOriginalType() == LocalIndexType.TRAVEL_DATA) {
return DownloadActivityType.WIKIVOYAGE_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.TTS_VOICE_DATA
|| localIndexInfo.getOriginalType() == LocalIndexType.VOICE_DATA) {
|| localIndexInfo.getOriginalType() == LocalIndexType.VOICE_DATA
|| localIndexInfo.getOriginalType() == LocalIndexType.TTS_VOICE_DATA_JS) {
return DownloadActivityType.VOICE_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.FONT_DATA) {
return DownloadActivityType.FONT_FILE;
@ -650,6 +651,8 @@ public class MapDataMenuController extends MenuController {
parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) {
parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA_JS) {
parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
}
return new File(parent, i.getFileName());
}

View file

@ -392,6 +392,13 @@ public class ResourceManager {
if (conf.exists()) {
indexFileNames.put(f.getName(), dateFormat.format(conf.lastModified())); //$NON-NLS-1$
}
if (f.getName().contains("-tts")) {
String lang = f.getName().replace("-tts", "");
File jsConf = new File(f, lang + "_" + IndexConstants.TTSVOICE_INDEX_EXT_JS);
if (jsConf.exists()) {
indexFileNames.put(f.getName(), dateFormat.format(jsConf.lastModified()));
}
}
}
}
}

View file

@ -11,8 +11,10 @@ import org.mozilla.javascript.NativeJSON;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@ -33,34 +35,14 @@ public class JSCommandBuilder extends CommandBuilder {
super(commandPlayer);
}
public void setJSContext(String path) {
String script = readFileContents(path);
public void setJSContext(ScriptableObject jsScope) {
jsContext = Context.enter();
jsContext.setOptimizationLevel(-1);
jsScope = jsContext.initStandardObjects();
jsContext.evaluateString(jsScope, script, "JS", 1, null);
this.jsScope = jsScope;
}
private Object convertStreetName(Map<String, String> streetName) {
return NativeJSON.parse(jsContext, jsScope, new JSONObject(streetName).toString(), new NullCallable());
}
private String readFileContents(String path) {
StringBuilder fileContent = new StringBuilder("");
try {
FileInputStream fis = new FileInputStream(new File(path));
byte[] buffer = new byte[1024];
int n;
while ((n = fis.read(buffer)) != -1)
{
fileContent.append(new String(buffer, 0, n));
}
fis.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return fileContent.toString();
return NativeJSON.parse(jsContext, jsScope, new JSONObject(streetName).toString(),
new NullCallable());
}
public void setParameters(String metricCons, boolean tts) {

View file

@ -20,6 +20,10 @@ import net.osmand.util.Algorithms;
import org.mozilla.javascript.ScriptableObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ -35,7 +39,6 @@ public class JSTTSCommandPlayerImpl extends AbstractJSCommandPlayer {
private boolean speechAllowed = false;
private Context mTtsContext;
private org.mozilla.javascript.Context jsContext;
private ScriptableObject jsScope;
private float cSpeechRate = 1;
@ -92,6 +95,20 @@ public class JSTTSCommandPlayerImpl extends AbstractJSCommandPlayer {
initializeEngine(app, ctx);
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, app.getSettings().AUDIO_STREAM_GUIDANCE
.getModeValue(getApplicationMode()).toString());
org.mozilla.javascript.Context context = org.mozilla.javascript.Context.enter();
context.setOptimizationLevel(-1);
jsScope = context.initSafeStandardObjects();
try {
BufferedReader br = new BufferedReader(new FileReader(new File(
app.getAppPath(IndexConstants.VOICE_INDEX_DIR).getAbsolutePath() +
"/" + voiceProvider + "/" + language + "_tts.js")));
context.evaluateReader(jsScope, br, "JS", 1, null);
br.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
} finally {
org.mozilla.javascript.Context.exit();
}
}
private void initializeEngine(final Context ctx, final Activity act) {
@ -220,7 +237,7 @@ public class JSTTSCommandPlayerImpl extends AbstractJSCommandPlayer {
@Override
public JSCommandBuilder newCommandBuilder() {
JSCommandBuilder commandBuilder = new JSCommandBuilder(this);
commandBuilder.setJSContext(app.getAppPath(IndexConstants.VOICE_INDEX_DIR).getAbsolutePath() + "/" + voiceProvider + "/" + language + "_tts.js");
commandBuilder.setJSContext(jsScope);
commandBuilder.setParameters(app.getSettings().METRIC_SYSTEM.get().toTTSString(), true);
return commandBuilder;
}
@ -307,6 +324,15 @@ public class JSTTSCommandPlayerImpl extends AbstractJSCommandPlayer {
ttsVoiceUsed = "";
}
public static boolean isMyData(File voiceDir) {
for (File f : voiceDir.listFiles()) {
if (f.getName().contains(IndexConstants.TTSVOICE_INDEX_EXT_JS)) {
return true;
}
}
return false;
}
private AlertDialog.Builder createAlertDialog(int titleResID, int messageResID,
JSTTSCommandPlayerImpl.IntentStarter intentStarter, final Activity ctx) {
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);