Skip to content

Commit

Permalink
Merge branch 'Colton127-iOS-17-synthesizeToFile-fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
dlutton committed Nov 23, 2023
2 parents 12748e1 + ed48bd1 commit 9ff5f94
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ios/Classes/SwiftFlutterTtsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,25 @@ public class SwiftFlutterTtsPlugin: NSObject, FlutterPlugin, AVSpeechSynthesizer
let fileURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent(fileName)
NSLog("Saving utterance to file: \(fileURL.absoluteString)")

if output == nil {
do {
output = try AVAudioFile(
forWriting: fileURL,
settings: pcmBuffer.format.settings,
commonFormat: .pcmFormatInt16,
interleaved: false)
} catch {
NSLog(error.localizedDescription)
if output == nil {
do {
if #available(iOS 17.0, *) {
guard let audioFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: Double(22050), channels: 1, interleaved: false) else {
NSLog("Error creating audio format for iOS 17+")
failed = true
return
}
output = try AVAudioFile(forWriting: fileURL, settings: audioFormat.settings)
} else {
output = try AVAudioFile(forWriting: fileURL, settings: pcmBuffer.format.settings, commonFormat: .pcmFormatInt16, interleaved: false)
}
} catch {
NSLog("Error creating AVAudioFile: \(error.localizedDescription)")
failed = true
return
}
}


try! output!.write(from: pcmBuffer)
}
Expand Down

0 comments on commit 9ff5f94

Please sign in to comment.