Updated the Capturing procotol in the Recording package target to pass captured audio as a file URL instead of data.
This commit is contained in:
@@ -2,7 +2,7 @@ import AVFoundation
|
||||
|
||||
/// The recording service that captures real audio from the device's microphone.
|
||||
///
|
||||
/// The service records into a temporary `.m4a` file through an `AVAudioRecorder`, and returns the file's contents when the recording stops.
|
||||
/// The service records into a temporary `.m4a` file through an `AVAudioRecorder`, and returns the file's location when the recording stops.
|
||||
/// The user's permission to record is requested before a recording starts and, on the platforms that require it, the shared audio session is
|
||||
/// configured for recording while the capture is in progress.
|
||||
@MainActor
|
||||
@@ -73,12 +73,11 @@ public final class AudioCapturing: Capturing {
|
||||
}
|
||||
}
|
||||
|
||||
/// Stops the recording, deleting the temporary audio file after its contents are read.
|
||||
/// Stops the recording, handing the temporary audio file over to the caller, which becomes responsible for deleting it.
|
||||
///
|
||||
/// - Returns: The audio captured since the recording started.
|
||||
/// - Throws: ``AudioCapturingError/noOngoingRecording`` when no recording is in progress, or any error thrown
|
||||
/// while reading the recorded audio file.
|
||||
public func stop() async throws -> Data {
|
||||
/// - Returns: The location of the audio file captured since the recording started.
|
||||
/// - Throws: ``AudioCapturingError/noOngoingRecording`` when no recording is in progress.
|
||||
public func stop() async throws -> URL {
|
||||
guard let recorder else {
|
||||
throw AudioCapturingError.noOngoingRecording
|
||||
}
|
||||
@@ -91,11 +90,7 @@ public final class AudioCapturing: Capturing {
|
||||
try? AVAudioSession.sharedInstance().setActive(false)
|
||||
#endif
|
||||
|
||||
defer {
|
||||
try? FileManager.default.removeItem(at: Constant.File.url)
|
||||
}
|
||||
|
||||
return try Data(contentsOf: Constant.File.url)
|
||||
return Constant.File.url
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user