Cay-Zhang / SwiftSpeech

A speech recognition framework designed for SwiftUI.
MIT License
474 stars 59 forks source link

It's possible to save the audio during speech to text? #5

Closed metrue closed 3 years ago

metrue commented 3 years ago

Maybe like,

SwiftSpeech.RecordButton()                                      
    .swiftSpeechRecordOnHold(sessionConfiguration:animation:distanceToCancel:)
    .onRecognizeLatest(update: $text)                           
    .onFinal(saveTo: url)
Cay-Zhang commented 3 years ago

SwiftSpeech doesn't support such functionality. To record and recognize audio simultaneously, you will have to dive deeper into the AVAudioEngine class. Here's a tutorial on how to record audio and save it to a file using AVAudioEngine. You'll also find the implementation of SwiftSpeech.SpeechRecognizer helpful.

Besides, I would like to point out that SwiftSpeech is designed for projects that want to integrate a speech recognition feature where the actual audio doesn't matter (such as for searching or text input). For projects that do care about the recorded audio (such as audio recorders or IM apps), it's better to copy SpeechRecognizer.swift into your project and start working based on that.

metrue commented 3 years ago

Yeah, for some case, the actual audio doesn't matter is absolutely true, but there's some cases like voice memo or journal, audio is important and user'd like to play back for some memory. And it actually need very few code changes,

audio = AVAudioFile(forWriting: url, settings: settings)
audio.write(from: buffer)

Also I know it's not builtin feature in SwiftSpeech is not because it requires too much change, but it's not designed for, I just like to bring up some cases that audio is kinda critical either, thanks for you great work on SwiftSpeech BTW.