Combine en-tts with en file

This commit is contained in:
Victor Shcherb 2012-06-03 00:38:13 +02:00
parent c3964e8a7a
commit f62da507ea
7 changed files with 51 additions and 111 deletions

View file

@ -1,85 +0,0 @@
:- op('==', xfy, 500).
version(101).
language(en).
% before each announcement (beep)
preamble - [].
%% TURNS
turn('left', ['turn left ']).
turn('left_sh', ['turn sharply left ']).
turn('left_sl', ['turn slightly left ']).
turn('right', ['turn right ']).
turn('right_sh', ['turn sharply right ']).
turn('right_sl', ['turn slightly right ']).
prepare_turn(Turn, Dist) == ['Prepare to ', M, ' after ', D] :- distance(Dist) == D, turn(Turn, M).
turn(Turn, Dist) == ['After ', D, M] :- distance(Dist) == D, turn(Turn, M).
turn(Turn) == M :- turn(Turn, M).
prepare_make_ut(Dist) == ['Prepare to make a U turn after ', D] :- distance(Dist) == D.
make_ut(Dist) == ['After ', D, ' make a U turn '] :- distance(Dist) == D.
make_ut == ['Make a U turn '].
make_ut_wp == ['When possible, please make a U turn '].
prepare_roundabout(Dist) == ['Prepare to enter a roundabout after ', D] :- distance(Dist) == D.
roundabout(Dist, _Angle, Exit) == ['After ', D, ' enter the roundabout, and take the ', E, 'exit'] :- distance(Dist) == D, nth(Exit, E).
roundabout(_Angle, Exit) == ['take the ', E, 'exit'] :- nth(Exit, E).
go_ahead == ['Go straight ahead '].
go_ahead(Dist) == ['Follow the course of the road for ', D]:- distance(Dist) == D.
and_arrive_destination == ['and arrive at your destination '].
then == ['then '].
reached_destination == ['you have reached your destination '].
bear_right == ['keep right '].
bear_left == ['keep left '].
route_new_calc(Dist) == ['The trip is ', D] :- distance(Dist) == D.
route_recalc(Dist) == ['Route recalculated, distance ', D] :- distance(Dist) == D.
location_lost == ['g p s signal lost '].
%%
nth(1, 'first ').
nth(2, 'second ').
nth(3, 'third ').
nth(4, 'fourth ').
nth(5, 'fifth ').
nth(6, 'sixth ').
nth(7, 'seventh ').
nth(8, 'eight ').
nth(9, 'nineth ').
nth(10, 'tenth ').
nth(11, 'eleventh ').
nth(12, 'twelfth ').
nth(13, 'thirteenth ').
nth(14, 'fourteenth ').
nth(15, 'fifteenth ').
nth(16, 'sixteenth ').
nth(17, 'seventeenth ').
%%% distance measure
distance(Dist) == [ X, ' feet'] :- Dist < 160, D is round(2*Dist/100/0.3048)*50, num_atom(D, X).
distance(Dist) == [ X, ' tenth of a mile'] :- Dist < 241, D is round(Dist/161), num_atom(D, X).
distance(Dist) == [ X, ' tenths of a mile'] :- Dist < 1529, D is round(Dist/161), num_atom(D, X).
distance(Dist) == ['about 1 mile '] :- Dist < 2414.
distance(Dist) == ['about ', X, ' miles '] :- Dist < 16093, D is round(Dist/1609), num_atom(D, X).
distance(Dist) == [ X, ' miles '] :- D is round(Dist/1609), num_atom(D, X).
%% resolve command main method
%% if you are familar with Prolog you can input specific to the whole mechanism,
%% by adding exception cases.
flatten(X, Y) :- flatten(X, [], Y), !.
flatten([], Acc, Acc).
flatten([X|Y], Acc, Res):- flatten(Y, Acc, R), flatten(X, R, Res).
flatten(X, Acc, [X|Acc]).
resolve(X, Y) :- resolve_impl(X,Z), flatten(Z, Y).
resolve_impl([],[]).
resolve_impl([X|Rest], List) :- resolve_impl(Rest, Tail), ((X == L) -> append(L, Tail, List); List = Tail).

View file

@ -63,12 +63,22 @@ nth(16, 'sixteenth ').
nth(17, 'seventeenth ').
distance(Dist) == D :- measure('km-m'), distance_km(Dist) == D.
distance(Dist) == D :- distance_mi(Dist) == D.
%%% distance measure
distance(Dist) == [ X, ' meters'] :- Dist < 100, D is round(Dist/10)*10, num_atom(D, X).
distance(Dist) == [ X, ' meters'] :- Dist < 1000, D is round(2*Dist/100)*50, num_atom(D, X).
distance(Dist) == ['about 1 kilometer '] :- Dist < 1500.
distance(Dist) == ['about ', X, ' kilometers '] :- Dist < 10000, D is round(Dist/1000), num_atom(D, X).
distance(Dist) == [ X, ' kilometers '] :- D is round(Dist/1000), num_atom(D, X).
distance_km(Dist) == [ X, ' meters'] :- Dist < 100, D is round(Dist/10)*10, num_atom(D, X).
distance_km(Dist) == [ X, ' meters'] :- Dist < 1000, D is round(2*Dist/100)*50, num_atom(D, X).
distance_km(Dist) == ['about 1 kilometer '] :- Dist < 1500.
distance_km(Dist) == ['about ', X, ' kilometers '] :- Dist < 10000, D is round(Dist/1000), num_atom(D, X).
distance_km(Dist) == [ X, ' kilometers '] :- D is round(Dist/1000), num_atom(D, X).
%%% distance measure
distance_mi(Dist) == [ X, ' feet'] :- Dist < 160, D is round(2*Dist/100/0.3048)*50, num_atom(D, X).
distance_mi(Dist) == [ X, ' tenth of a mile'] :- Dist < 241, D is round(Dist/161), num_atom(D, X).
distance_mi(Dist) == [ X, ' tenths of a mile'] :- Dist < 1529, D is round(Dist/161), num_atom(D, X).
distance_mi(Dist) == ['about 1 mile '] :- Dist < 2414.
distance_mi(Dist) == ['about ', X, ' miles '] :- Dist < 16093, D is round(Dist/1609), num_atom(D, X).
distance_mi(Dist) == [ X, ' miles '] :- D is round(Dist/1609), num_atom(D, X).
%% resolve command main method

View file

@ -1266,19 +1266,26 @@ public class OsmandSettings {
}
public enum MetricsConstants {
KILOMETERS_AND_METERS(R.string.si_km_m),
MILES_AND_YARDS(R.string.si_mi_yard),
MILES_AND_FOOTS(R.string.si_mi_foots);
KILOMETERS_AND_METERS(R.string.si_km_m,"km-m"),
MILES_AND_YARDS(R.string.si_mi_yard,"mi-y"),
MILES_AND_FOOTS(R.string.si_mi_foots,"mi-f");
private final int key;
MetricsConstants(int key) {
private final String ttsString;
MetricsConstants(int key, String ttsString) {
this.key = key;
this.ttsString = ttsString;
}
public String toHumanString(Context ctx){
return ctx.getResources().getString(key);
}
public String toTTSString(){
return ttsString;
}
}
}

View file

@ -11,6 +11,8 @@ import java.util.List;
import net.osmand.LogUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
@ -48,14 +50,14 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer {
/** Must be sorted array! */
private final int[] sortedVoiceVersions;
protected AbstractPrologCommandPlayer(Context ctx, String voiceProvider, String configFile, int[] sortedVoiceVersions)
protected AbstractPrologCommandPlayer(Context ctx, OsmandSettings settings, String voiceProvider, String configFile, int[] sortedVoiceVersions)
throws CommandPlayerException
{
this.sortedVoiceVersions = sortedVoiceVersions;
long time = System.currentTimeMillis();
try {
this.ctx = ctx;
prologSystem = new Prolog(getLibraries());
prologSystem = new Prolog(getLibraries());
} catch (InvalidLibraryException e) {
log.error("Initializing error", e); //$NON-NLS-1$
throw new RuntimeException(e);
@ -63,7 +65,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer {
if (log.isInfoEnabled()) {
log.info("Initializing prolog system : " + (System.currentTimeMillis() - time)); //$NON-NLS-1$
}
init(voiceProvider, configFile);
init(voiceProvider, settings, configFile);
}
public String[] getLibraries(){
@ -71,7 +73,7 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer {
"alice.tuprolog.lib.ISOLibrary"};
}
private void init(String voiceProvider, String configFile) throws CommandPlayerException {
private void init(String voiceProvider, OsmandSettings settings, String configFile) throws CommandPlayerException {
prologSystem.clearTheory();
voiceDir = null;
if (voiceProvider != null) {
@ -99,7 +101,10 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer {
config = new FileInputStream(new File(voiceDir, configFile)); //$NON-NLS-1$
// }
if (!wrong) {
prologSystem.setTheory(new Theory(config));
MetricsConstants mc = settings.METRIC_SYSTEM.get();
prologSystem.addTheory(new Theory("measure('"+mc.toTTSString()+"')."));
prologSystem.addTheory(new Theory(config));
}
} catch (InvalidTheoryException e) {
log.error("Loading voice config exception " + voiceProvider, e); //$NON-NLS-1$

View file

@ -3,6 +3,7 @@ package net.osmand.plus.voice;
import java.io.File;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import android.app.Activity;
@ -14,16 +15,18 @@ public class CommandPlayerFactory
throws CommandPlayerException
{
if (voiceProvider != null){
File parent = osmandApplication.getSettings().extendOsmandPath(ResourceManager.VOICE_PATH);
OsmandSettings settings = osmandApplication.getSettings();
File parent = settings.extendOsmandPath(ResourceManager.VOICE_PATH);
File voiceDir = new File(parent, voiceProvider);
if(!voiceDir.exists()){
throw new CommandPlayerException(ctx.getString(R.string.voice_data_unavailable));
}
if (MediaCommandPlayerImpl.isMyData(voiceDir)) {
return new MediaCommandPlayerImpl(osmandApplication, voiceProvider);
return new MediaCommandPlayerImpl(osmandApplication, settings, voiceProvider);
} else if (Integer.parseInt(Build.VERSION.SDK) >= 4) {
if (TTSCommandPlayerImpl.isMyData(voiceDir)) {
return new TTSCommandPlayerImpl(ctx, voiceProvider);
return new TTSCommandPlayerImpl(ctx, settings, voiceProvider);
}
}
throw new CommandPlayerException(ctx.getString(R.string.voice_data_not_supported));

View file

@ -7,7 +7,7 @@ import java.util.Collections;
import java.util.List;
import net.osmand.LogUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import org.apache.commons.logging.Log;
@ -34,13 +34,12 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer {
private int streamType;
public MediaCommandPlayerImpl(Context ctx, String voiceProvider)
public MediaCommandPlayerImpl(Context ctx, OsmandSettings settings, String voiceProvider)
throws CommandPlayerException
{
super(ctx, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);
super(ctx, settings, voiceProvider, CONFIG_FILE, MEDIA_VOICE_VERSION);
mediaPlayer = new MediaPlayer();
OsmandApplication osmApp = (OsmandApplication) ctx.getApplicationContext();
this.streamType = osmApp.getSettings().AUDIO_STREAM_GUIDANCE.get();
this.streamType = settings.AUDIO_STREAM_GUIDANCE.get();
mediaPlayer.setAudioStreamType(streamType);
}

View file

@ -7,6 +7,7 @@ import java.util.Locale;
import net.osmand.Algoritms;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsActivity;
import alice.tuprolog.Struct;
@ -57,9 +58,9 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
private String language;
private HashMap<String, String> params = new HashMap<String, String>();
protected TTSCommandPlayerImpl(Activity ctx, String voiceProvider)
protected TTSCommandPlayerImpl(Activity ctx, OsmandSettings settings, String voiceProvider)
throws CommandPlayerException {
super(ctx, voiceProvider, CONFIG_FILE, TTS_VOICE_VERSION);
super(ctx, settings, voiceProvider, CONFIG_FILE, TTS_VOICE_VERSION);
final Term langVal = solveSimplePredicate("language");
if (langVal instanceof Struct) {
language = ((Struct) langVal).getName();
@ -70,7 +71,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
}
OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
initializeEngine(app, ctx);
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, app.getSettings().AUDIO_STREAM_GUIDANCE.get().toString());
params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, settings.AUDIO_STREAM_GUIDANCE.get().toString());
}
@ -87,7 +88,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
}
}
private void initializeEngine(final OsmandApplication ctx, final Activity act)
private void initializeEngine(final Context ctx, final Activity act)
{
if (mTts != null && mTtsContext != ctx) {
internalClear();