@@ -168,17 +168,15 @@ public final class Decoder {
168168
169169 public func startDecodingSpeech ( _ utteranceComplete: @escaping ( Hypothesis ? ) -> ( ) ) throws {
170170
171- if #available( iOS 10 . 0 , * ) {
172- do {
173- try AVAudioSession . sharedInstance ( ) . setCategory ( . playback, mode: . moviePlayback)
174- } catch let error as NSError {
175- print ( " Error setting the shared AVAudioSession: \( error) " )
176- throw DecodeErrors . CantSetAudioSession ( error)
171+ do {
172+ if #available( iOS 10 . 0 , * ) {
173+ try AVAudioSession . sharedInstance ( ) . setCategory ( . playAndRecord, mode: . voiceChat, options: [ ] )
174+ } else {
175+ try AVAudioSession . sharedInstance ( ) . setCategory ( . playAndRecord)
177176 }
178- } else {
179- // Workaround until https://forums.swift.org/t/using-methods-marked-unavailable-in-swift-4-2/14949 isn't fixed
180- AVAudioSession . sharedInstance ( ) . perform (
181- NSSelectorFromString ( " setCategory:error: " ) , with: AVAudioSession . Category. playback)
177+ } catch let error as NSError {
178+ print ( " Error setting the shared AVAudioSession: \( error) " )
179+ throw DecodeErrors . CantSetAudioSession ( error)
182180 }
183181
184182 engine = AVAudioEngine ( )
@@ -201,17 +199,17 @@ public final class Decoder {
201199 [ unowned self] ( buffer: AVAudioPCMBuffer ! , time: AVAudioTime ! ) in
202200
203201 guard let sphinxBuffer = AVAudioPCMBuffer ( pcmFormat: formatOut, frameCapacity: buffer. frameCapacity) else {
204- // Returns nil in the following cases:
205- // - if the format has zero bytes per frame (format.streamDescription->mBytesPerFrame == 0)
206- // - if the buffer byte capacity (frameCapacity * format.streamDescription->mBytesPerFrame)
207- // cannot be represented by an uint32_t
202+ // Returns nil in the following cases:
203+ // - if the format has zero bytes per frame (format.streamDescription->mBytesPerFrame == 0)
204+ // - if the buffer byte capacity (frameCapacity * format.streamDescription->mBytesPerFrame)
205+ // cannot be represented by an uint32_t
208206 print ( " Can't create PCM buffer " )
209207 return
210208 }
211209
212- //This is needed because the 'frameLenght' default value is 0 (since iOS 10) and cause the 'convert' call
213- //to faile with an error (Error Domain=NSOSStatusErrorDomain Code=-50 "(null)")
214- //More here: http://stackoverflow.com/questions/39714244/avaudioconverter-is-broken-in-ios-10
210+ // This is needed because the 'frameLenght' default value is 0 (since iOS 10) and cause the 'convert' call
211+ // to faile with an error (Error Domain=NSOSStatusErrorDomain Code=-50 "(null)")
212+ // More here: http://stackoverflow.com/questions/39714244/avaudioconverter-is-broken-in-ios-10
215213 sphinxBuffer. frameLength = sphinxBuffer. frameCapacity
216214
217215 do {
0 commit comments