Skip to content

Commit

Permalink
Do not use AVAudioSession on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed Nov 8, 2022
1 parent 579c887 commit 4f721cf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Application/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ struct ContentView: View {
let auChannel: AUMessageChannel
let langs: [(id: String, name: String)]
let voices: [(id: String, name: String)]
#if os(iOS)
let audioSession = AVAudioSession.sharedInstance()
#endif
@State var synthText: String = "Hello"
@State var langId: String = "gmw/en-US"
@State var voiceId: String = ""
Expand All @@ -116,12 +118,14 @@ struct ContentView: View {
init(audioUnit: AVAudioUnit) {
self.audioUnit = audioUnit
self.auChannel = audioUnit.auAudioUnit.messageChannel(for: "espeakData")
#if os(iOS)
try? audioSession.setCategory(
.playback,
mode: .spokenAudio,
policy: .default,
options: [.duckOthers]
)
#endif
let res = self.auChannel.callAudioUnit?(["initHost":true])
let langIds = (res?["langIds"] as? [String]) ?? []
let langNames = (res?["langNames"] as? [String]) ?? []
Expand Down Expand Up @@ -161,8 +165,10 @@ struct ContentView: View {
AVSpeechSynthesisProviderVoice.updateSpeechVoices()
})
.navigationTitle("eSpeak-NG")
#if os(iOS)
.onAppear { try? audioSession.setActive(true) ; try? engine.start() }
.onDisappear { engine.stop() ; try? audioSession.setActive(false) }
#endif
.toolbar {
NavigationLink(destination: {
VoiceOverLangSelector(
Expand Down

0 comments on commit 4f721cf

Please sign in to comment.