我正在开发这个应用程序,它利用了iOS的语音转文本功能。我发现了来自苹果的非常好的示例应用程序:https://developer.apple.com/library/content/samplecode/SpeakToMe/Introduction/Intro.html
此应用程序正在使用live: SFSpeechAudioBufferRecognitionRequest功能,并自动将语音转录为文本。此外,我还发现了许多将音频文件转录为文本的教程。
但是我需要一些不同的东西,我想要实时文本到语音功能(就像上面的示例应用程序一样),我需要保存音频文件。这有可能吗?
发布于 2017-11-05 05:20:45
您可以实现Saving Recorded Audio (Swift)中描述的技术。基本上,像这样设置一个AVAudioRecorder,然后将它与您返回的音频输出连接起来,以保存剪辑。
func setupRecorder() {
let recordSettings : [String : AnyObject] =
[
AVFormatIDKey: NSNumber(unsignedInt: kAudioFormatMPEG4AAC),
AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue as NSNumber,
AVEncoderBitRateKey : 320000 as NSNumber,
AVNumberOfChannelsKey: 2 as NSNumber,
AVSampleRateKey : 44100.0 as NSNumber
]
do {
try soundRecorder = AVAudioRecorder(URL: getFileURL(), settings: recordSettings)
soundRecorder.delegate = self
soundRecorder.prepareToRecord()
} catch {
print(error)
}
}
func getCacheDirectory() -> String {
let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
return paths[0]
}
func getFileURL() -> NSURL{
let path = getCacheDirectory().stringByAppendingPathComponent(fileName)
let filePath = NSURL(fileURLWithPath: path)
return filePath
}
func audioRecorderDidFinishRecording(recorder: AVAudioRecorder, successfully flag: Bool) {
PlayButton.enabled = true
recordedAudio = RecordedAudio()
recordedAudio.filePathUrl = recorder.url
recordedAudio.title = recorder.url.lastPathComponent
print(recordedAudio.title)
}https://stackoverflow.com/questions/47115271
复制相似问题