-
Notifications
You must be signed in to change notification settings - Fork 30
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
Ios mute fix after discussion #296
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
249d977
ios mute button
64cf978
adjustment made based on dicsussion for Ios Mute button
fae9ad2
fixed the in the file
d76959f
changed name of file so the names are consistent
60bb06b
adjusted based on the other buttons
bd4b7f8
Clean up and fixes to get this ready
ianthetechie b71ea85
Use a boring ObservableObject and use UDF
ianthetechie 35df836
Simplified and tested mute button:
Archdoog 583acea
Delete .gitmodules
ianthetechie 45ee6c8
Delete extraneous submodule
ianthetechie 10c83d9
Try to fix CI
ianthetechie d64dd25
Attempt to improve UI responsiveness
ianthetechie f93e9e1
Improve speed limit display
ianthetechie 4c284a2
Hide when not navigating
ianthetechie 1d3cc67
Add missing docs
ianthetechie 57e6f89
Swiftformat
ianthetechie 7e01782
Update snapshots
ianthetechie 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
Empty file.
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 was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
apple/Sources/FerrostarCore/Speech/SpeechSynthesizer.swift
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import AVFoundation | ||
import Foundation | ||
|
||
/// An abstracted speech synthesizer that is used by the ``SpokenInstructionObserver`` | ||
/// | ||
/// Any functions that are needed for use in the ``SpokenInstructionObserver`` should be exposed through | ||
/// this protocol. | ||
public protocol SpeechSynthesizer { | ||
// TODO: We could further abstract this to allow other speech synths. | ||
// E.g. with a `struct SpeechUtterance` if and when another speech service comes along. | ||
|
||
var isSpeaking: Bool { get } | ||
func speak(_ utterance: AVSpeechUtterance) | ||
@discardableResult | ||
func stopSpeaking(at boundary: AVSpeechBoundary) -> Bool | ||
} | ||
|
||
extension AVSpeechSynthesizer: SpeechSynthesizer { | ||
// No def required | ||
} | ||
|
||
class PreviewSpeechSynthesizer: SpeechSynthesizer { | ||
public var isSpeaking: Bool = false | ||
|
||
public func speak(_: AVSpeechUtterance) { | ||
// No action for previews | ||
} | ||
|
||
public func stopSpeaking(at _: AVSpeechBoundary) -> Bool { | ||
// No action for previews | ||
true | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
apple/Sources/FerrostarCore/Speech/SpokenInstructionObserver.swift
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import AVFoundation | ||
import Combine | ||
import FerrostarCoreFFI | ||
import Foundation | ||
|
||
/// An Spoken instruction provider that takes a speech synthesizer. | ||
public class SpokenInstructionObserver: ObservableObject { | ||
@Published public private(set) var isMuted: Bool | ||
|
||
private let synthesizer: SpeechSynthesizer | ||
private let queue = DispatchQueue(label: "ferrostar-spoken-instruction-observer", qos: .default) | ||
|
||
/// Create a spoken instruction observer with any ``SpeechSynthesizer`` | ||
/// | ||
/// - Parameters: | ||
/// - synthesizer: The speech synthesizer. | ||
/// - isMuted: Whether the speech synthesizer is currently muted. Assume false if unknown. | ||
public init( | ||
synthesizer: SpeechSynthesizer, | ||
isMuted: Bool | ||
) { | ||
self.synthesizer = synthesizer | ||
self.isMuted = isMuted | ||
} | ||
|
||
public func spokenInstructionTriggered(_ instruction: FerrostarCoreFFI.SpokenInstruction) { | ||
guard !isMuted else { | ||
return | ||
} | ||
|
||
let utterance: AVSpeechUtterance = if #available(iOS 16.0, *), | ||
let ssml = instruction.ssml, | ||
let ssmlUtterance = AVSpeechUtterance(ssmlRepresentation: ssml) | ||
{ | ||
ssmlUtterance | ||
} else { | ||
AVSpeechUtterance(string: instruction.text) | ||
} | ||
|
||
queue.async { | ||
self.synthesizer.speak(utterance) | ||
Check warning on line 41 in apple/Sources/FerrostarCore/Speech/SpokenInstructionObserver.swift
|
||
} | ||
} | ||
|
||
/// Toggle the mute. | ||
public func toggleMute() { | ||
let isCurrentlyMuted = isMuted | ||
isMuted = !isCurrentlyMuted | ||
|
||
// This used to have `synthesizer.isSpeaking`, but I think we want to run it regardless. | ||
ianthetechie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if isMuted { | ||
queue.async { | ||
self.stopAndClearQueue() | ||
} | ||
} | ||
} | ||
|
||
public func stopAndClearQueue() { | ||
synthesizer.stopSpeaking(at: .immediate) | ||
} | ||
} | ||
|
||
public extension SpokenInstructionObserver { | ||
/// Create a new spoken instruction observer with AFFoundation's AVSpeechSynthesizer. | ||
/// | ||
/// - Parameters: | ||
/// - synthesizer: An instance of AVSpeechSynthesizer. One is provided by default, but you can inject your own. | ||
/// - isMuted: If the synthesizer is muted. This should be false unless you're providing a "hot" synth that is | ||
/// speaking. | ||
/// - Returns: The instance of SpokenInstructionObserver | ||
static func initAVSpeechSynthesizer(synthesizer: AVSpeechSynthesizer = AVSpeechSynthesizer(), | ||
isMuted: Bool = false) -> SpokenInstructionObserver | ||
{ | ||
SpokenInstructionObserver(synthesizer: synthesizer, isMuted: isMuted) | ||
} | ||
} |
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
Oops, something went wrong.
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.
Had to bump this to resolve some whack build error that I couldn't repro locally. Can bump to 16.1 whenever GitHub updates (final release just dropped).