-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let speak instructions without route progress. #32
Merged
boldtrn
merged 2 commits into
maplibre:main
from
StephanPartzsch:speak-without-route-progress
Mar 18, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,13 +192,9 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate { | |
|
||
- parameter instruction: The instruction to read aloud. | ||
- parameter locale: The `Locale` used to create the voice read aloud the given instruction. If `nil` the `Locale.preferredLocalLanguageCountryCode` is used for creating the voice. | ||
- parameter ignoreProgress: A `Bool` that indicates if the routeProgress is added to the instruction. | ||
*/ | ||
open func speak(_ instruction: SpokenInstruction, with locale: Locale?) { | ||
guard let routeProgress else { | ||
assertionFailure("routeProgress should not be nil.") | ||
return | ||
} | ||
|
||
open func speak(_ instruction: SpokenInstruction, with locale: Locale?, ignoreProgress: Bool = false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be honest, I am not sure if we really need the ignoreProgress switch here? We would need to make route progress optional as well for |
||
if speechSynth.isSpeaking, let lastSpokenInstruction = lastSpokenInstruction { | ||
voiceControllerDelegate?.voiceController?(self, didInterrupt: lastSpokenInstruction, with: instruction) | ||
} | ||
|
@@ -209,29 +205,26 @@ open class RouteVoiceController: NSObject, AVSpeechSynthesizerDelegate { | |
voiceControllerDelegate?.voiceController?(self, spokenInstructionsDidFailWith: error) | ||
} | ||
|
||
var utterance: AVSpeechUtterance? | ||
let modifiedInstruction = voiceControllerDelegate?.voiceController?(self, willSpeak: instruction, routeProgress: routeProgress) ?? instruction | ||
|
||
let utterance: AVSpeechUtterance | ||
|
||
if locale?.identifier == "en-US" { | ||
// Alex can’t handle attributed text. | ||
utterance = AVSpeechUtterance(string: instruction.text) | ||
utterance!.voice = AVSpeechSynthesisVoice(identifier: AVSpeechSynthesisVoiceIdentifierAlex) | ||
} | ||
|
||
let modifiedInstruction = voiceControllerDelegate?.voiceController?(self, willSpeak: instruction, routeProgress: routeProgress) ?? instruction | ||
|
||
if #available(iOS 10.0, *), utterance?.voice == nil { | ||
utterance = AVSpeechUtterance(attributedString: modifiedInstruction.attributedText(for: routeProgress.currentLegProgress)) | ||
} else { | ||
utterance = AVSpeechUtterance(string: modifiedInstruction.text) | ||
utterance.voice = AVSpeechSynthesisVoice(identifier: AVSpeechSynthesisVoiceIdentifierAlex) | ||
} else { | ||
if #available(iOS 10.0, *), !ignoreProgress, let routeProgress { | ||
utterance = AVSpeechUtterance(attributedString: modifiedInstruction.attributedText(for: routeProgress.currentLegProgress)) | ||
} else { | ||
utterance = AVSpeechUtterance(string: modifiedInstruction.text) | ||
} | ||
|
||
boldtrn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Only localized languages will have a proper fallback voice | ||
utterance.voice = AVSpeechSynthesisVoice(language: locale?.identifier ?? Locale.preferredLocalLanguageCountryCode) | ||
} | ||
|
||
// Only localized languages will have a proper fallback voice | ||
if utterance?.voice == nil { | ||
utterance?.voice = AVSpeechSynthesisVoice(language: locale?.identifier ?? Locale.preferredLocalLanguageCountryCode) | ||
} | ||
|
||
if let utterance = utterance { | ||
speechSynth.speak(utterance) | ||
} | ||
speechSynth.speak(utterance) | ||
} | ||
} | ||
|
||
|
@@ -264,8 +257,8 @@ public protocol VoiceControllerDelegate { | |
|
||
- parameter voiceController: The voice controller that will speak an instruction. | ||
- parameter instruction: The spoken instruction that will be said. | ||
- parameter routeProgress: The `RouteProgress` just before when the instruction is scheduled to be spoken. | ||
- parameter routeProgress: The `RouteProgress` just before when the instruction is scheduled to be spoken. Could be `nil` if no progress is available or if it should be ignored. | ||
**/ | ||
@objc(voiceController:willSpeakSpokenInstruction:routeProgress:) | ||
optional func voiceController(_ voiceController: RouteVoiceController, willSpeak instruction: SpokenInstruction, routeProgress: RouteProgress) -> SpokenInstruction? | ||
optional func voiceController(_ voiceController: RouteVoiceController, willSpeak instruction: SpokenInstruction, routeProgress: RouteProgress?) -> SpokenInstruction? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a CHANGELOG entry for the changed APIs? Both here and for the RouteVoiceController?