From de011e1afcb4954dcb9b69443186d04b847eb3f6 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 24 Jan 2020 17:49:28 +0200 Subject: [PATCH] fix 8299 --- .../src/main/java/net/osmand/util/Algorithms.java | 13 +++++++++++++ .../osmand/plus/development/TestVoiceActivity.java | 7 ++++--- OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java | 9 +++++---- .../src/net/osmand/plus/voice/CommandBuilder.java | 8 ++++---- .../src/net/osmand/plus/voice/JSCommandBuilder.java | 8 ++++---- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index 924c9e81d1..6e4f38ad02 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -217,6 +217,19 @@ public class Algorithms { } } + + /** + * Find end index of first number in string if contains letters else return -1 + */ + public static int findFirstNumberEndIndexInString(String value) { + for (int i = 0; i < value.length(); i++) { + if (i + 1 < value.length() && Character.isLetter(i + 1)) { + return i; + } + } + return -1; + } + public static boolean isDigit(char charAt) { return charAt >= '0' && charAt <= '9'; } diff --git a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java index a4b1478a32..01cec536b9 100644 --- a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java @@ -169,9 +169,10 @@ public class TestVoiceActivity extends OsmandActionBarActivity { addButton(ll, "\u25BA (3.4) After 3100m turn right onto 'SR 80' toward 'Rome'", builder(p).prepareTurn(AbstractPrologCommandPlayer.A_RIGHT, 3100, street(p, "SR 80", "", "Rome"))); addButton(ll, "\u25BA (3.5) In 370m turn slightly right onto 'Route 23' 'Main Street', then bear left", builder(p).turn(AbstractPrologCommandPlayer.A_RIGHT_SL, 370, street(p, "Route 23", "Main Street", "")).then().bearLeft(street(p, ""))); addButton(ll, "\u25BA (3.6) Turn sharply right onto 'Dr.-Quinn-Stra"+"\u00df"+"e'", builder(p).turn(AbstractPrologCommandPlayer.A_RIGHT_SH, street(p, "", "Dr.-Quinn-Straße", ""))); - addButton(ll, "\u25BA (3.7) Turn slightly right to exit 6 onto 'Amsterdam-Osdorp'", builder(p).takeExit(AbstractPrologCommandPlayer.A_RIGHT_SL, "6", street(p, "", "Amsterdam-Osdorp", ""))); - addButton(ll, "\u25BA (3.8) In 350m turn slightly right to exit 6 onto 'Amsterdam-Osdorp'", builder(p).takeExit(AbstractPrologCommandPlayer.A_RIGHT_SL, 350, "6", street(p, "", "Amsterdam-Osdorp", ""))); - addButton(ll, "\u25BA (3.9) Turn slightly right to exit 260B ", builder(p).takeExit(AbstractPrologCommandPlayer.A_RIGHT_SL, "260 B.", street(p, "", "", ""))); + addButton(ll, "\u25BA (3.7) Turn slightly right to exit 6 onto 'Amsterdam-Osdorp'", builder(p).takeExit(AbstractPrologCommandPlayer.A_RIGHT_SL, "6", -1, street(p, "", "Amsterdam-Osdorp", ""))); + addButton(ll, "\u25BA (3.8) In 350m turn slightly right to exit 6 onto 'Amsterdam-Osdorp'", builder(p).takeExit(AbstractPrologCommandPlayer.A_RIGHT_SL, 350, "6", -1, street(p, "", "Amsterdam-Osdorp", ""))); + addButton(ll, "\u25BA (3.9) Turn slightly right to exit 260B ", builder(p).takeExit(AbstractPrologCommandPlayer.A_RIGHT_SL, "260 B", 3, street(p, "", "", ""))); + addButton(ll, "\u25BA (3.10) Turn slightly left to exit 15B ", builder(p).takeExit(AbstractPrologCommandPlayer.A_LEFT_SL, "15 B", 2, street(p, "", "", ""))); addButton(ll, "Keep left/right: prepareTurn, makeTurnIn, turn:", builder(p)); addButton(ll, "\u25BA (4.1) After 1810m keep left ' '", builder(p).prepareTurn(AbstractPrologCommandPlayer.A_LEFT_KEEP, 1810, street(p, ""))); diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index bfda11ff1b..1f62dbd039 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -3,6 +3,7 @@ package net.osmand.plus.routing; import android.media.AudioManager; import android.media.SoundPool; +import android.util.Log; import net.osmand.Location; import net.osmand.binary.RouteDataObject; @@ -718,8 +719,6 @@ public class VoiceRouter { sb.append(exit.charAt(i)); } } - // For pronounce letter like in transcription - sb.append("."); } return sb.toString(); } @@ -732,7 +731,8 @@ public class VoiceRouter { ExitInfo exitInfo = next.getExitInfo(); if (tParam != null) { if (exitInfo != null && !Algorithms.isEmpty(exitInfo.getRef())) { - p.takeExit(tParam, dist, getSpeakableExitRef(exitInfo.getRef()), getSpeakableExitName(next, exitInfo, true)); + String speakableExitRef = getSpeakableExitRef(exitInfo.getRef()); + p.takeExit(tParam, dist, speakableExitRef, Algorithms.findFirstNumberEndIndexInString(speakableExitRef), getSpeakableExitName(next, exitInfo, true)); } else { p.turn(tParam, dist, getSpeakableStreetName(currentSegment, next, true)); } @@ -805,7 +805,8 @@ public class VoiceRouter { boolean isplay = true; if (tParam != null) { if (exitInfo != null && !Algorithms.isEmpty(exitInfo.getRef())) { - p.takeExit(tParam, getSpeakableExitRef(exitInfo.getRef()), getSpeakableExitName(next, exitInfo, !suppressDest)); + String speakableExitRef = getSpeakableExitRef(exitInfo.getRef()); + p.takeExit(tParam, speakableExitRef, Algorithms.findFirstNumberEndIndexInString(speakableExitRef), getSpeakableExitName(next, exitInfo, !suppressDest)); } else { p.turn(tParam, getSpeakableStreetName(currentSegment, next, !suppressDest)); } diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java index a3e1dcf587..e2b21ee05d 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandBuilder.java @@ -179,12 +179,12 @@ public class CommandBuilder { return alt(prepareStruct(C_TURN, param, dist, streetName), prepareStruct(C_TURN, param, dist)); } - public CommandBuilder takeExit(String turnType, String exit, StreetName streetName) { - return alt(prepareStruct(C_TAKE_EXIT, turnType, exit, streetName), prepareStruct(C_TAKE_EXIT, turnType, exit)); + public CommandBuilder takeExit(String turnType, String exit, int firstNumEndIndex, StreetName streetName) { + return alt(prepareStruct(C_TAKE_EXIT, turnType, exit, firstNumEndIndex, streetName), prepareStruct(C_TAKE_EXIT, turnType, exit, firstNumEndIndex)); } - public CommandBuilder takeExit(String turnType, double dist, String exit, StreetName streetName) { - return alt(prepareStruct(C_TAKE_EXIT, turnType, dist, exit, streetName), prepareStruct(C_TAKE_EXIT, turnType, dist, exit)); + public CommandBuilder takeExit(String turnType, double dist, String exit,int firstNumEndIndex, StreetName streetName) { + return alt(prepareStruct(C_TAKE_EXIT, turnType, dist, exit, firstNumEndIndex, streetName), prepareStruct(C_TAKE_EXIT, turnType, dist, exit, firstNumEndIndex)); } /** diff --git a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java index 581a05b8c0..4c88127da6 100644 --- a/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java +++ b/OsmAnd/src/net/osmand/plus/voice/JSCommandBuilder.java @@ -119,13 +119,13 @@ public class JSCommandBuilder extends CommandBuilder { return addCommand(C_TURN, param, dist, convertStreetName(streetName)); } - public JSCommandBuilder takeExit(String turnType, String exit, StreetName streetName) { - return takeExit(turnType, -1, exit, streetName); + public JSCommandBuilder takeExit(String turnType, String exit, int firstNumEndIndex, StreetName streetName) { + return takeExit(turnType, -1, exit, firstNumEndIndex, streetName); } - public JSCommandBuilder takeExit(String turnType, double dist, String exit, StreetName streetName) { + public JSCommandBuilder takeExit(String turnType, double dist, String exit, int firstNumEndIndex, StreetName streetName) { return isJSCommandExists(C_TAKE_EXIT) ? - addCommand(C_TAKE_EXIT, turnType, dist, exit, convertStreetName(streetName)) : + addCommand(C_TAKE_EXIT, turnType, dist, exit, firstNumEndIndex, convertStreetName(streetName)) : addCommand(C_TURN, turnType, dist, convertStreetName(streetName)); }