Voice message recording enhancements (#2042)

* Use Combine to report AudioRecorder state changes

* AudioRecorder is now using AVAudioEngine instead of AVAudioRecorder

* Stop recording when audio configuration changes

* AudioRecorder error handling

* UnitTests

* Use Accelerate to calculate RMS
This commit is contained in:
Nicolas Mauri
2023-11-08 10:19:28 +01:00
committed by GitHub
parent 14e0eba914
commit e04a55eaef
13 changed files with 817 additions and 269 deletions
@@ -14,6 +14,7 @@
// limitations under the License.
//
import Combine
import Foundation
enum VoiceMessageRecorderError: Error {
@@ -21,17 +22,26 @@ enum VoiceMessageRecorderError: Error {
case missingRecordingFile
case previewNotAvailable
case audioRecorderError(AudioRecorderError)
case waveformAnalysisError
case failedSendingVoiceMessage
}
enum VoiceMessageRecorderAction {
case didStartRecording(audioRecorder: AudioRecorderProtocol)
case didStopRecording(previewState: AudioPlayerState, url: URL)
case didFailWithError(error: VoiceMessageRecorderError)
}
protocol VoiceMessageRecorderProtocol {
var audioRecorder: AudioRecorderProtocol { get }
var previewAudioPlayerState: AudioPlayerState? { get }
var recordingURL: URL? { get }
var recordingDuration: TimeInterval { get }
func startRecording() async -> Result<Void, VoiceMessageRecorderError>
func stopRecording() async -> Result<Void, VoiceMessageRecorderError>
var actions: AnyPublisher<VoiceMessageRecorderAction, Never> { get }
func startRecording() async
func stopRecording() async
func cancelRecording() async
func startPlayback() async -> Result<Void, VoiceMessageRecorderError>
func pausePlayback()