cancelRecording method

Future<void> cancelRecording()

Cancels the current recording and deletes the file

Implementation

Future<void> cancelRecording() async {
  if (!_isRecording) {
    return;
  }

  try {
    await _recorder.stop();
    _isRecording = false;

    // Delete the file if it exists
    if (_currentRecordingPath != null) {
      final file = File(_currentRecordingPath!);
      if (await file.exists()) {
        await file.delete();
      }
    }

    _currentRecordingPath = null;
  } catch (e) {
    _isRecording = false;
    _currentRecordingPath = null;
    throw WhisperRecordingException(
      'Failed to cancel recording: $e',
      cause: e,
    );
  }
}