-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ios mute fix after discussion (#296)
* ios mute button * adjustment made based on dicsussion for Ios Mute button * fixed the in the file * changed name of file so the names are consistent * adjusted based on the other buttons * Clean up and fixes to get this ready * Use a boring ObservableObject and use UDF * Delete .gitmodules * Delete extraneous submodule * Try to fix CI * Attempt to improve UI responsiveness * Improve speed limit display * Hide when not navigating * Add missing docs * Swiftformat * Update snapshots --------- Co-authored-by: Marek Sabol <mareksabol@MacBook-Pro-uzivatela-Marek.local> Co-authored-by: Ian Wagner <ian.wagner@stadiamaps.com> Co-authored-by: Jacob Fielding <jf0517@gmail.com>
- Loading branch information
1 parent
14b41be
commit dbee23a
Showing
35 changed files
with
432 additions
and
79 deletions.
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 GitHub Actions / test (FerrostarCore-Package, platform=iOS Simulator,name=iPhone 15,OS=17.2)
|
||
} | ||
} | ||
|
||
/// 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. | ||
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.