Skip to content

fix: cleanup temporary audio files after transcription to prevent storage buildup#27

Open
dhruvi-16-me wants to merge 1 commit intoAOSSIE-Org:mainfrom
dhruvi-16-me:cleanup-audio-files
Open

fix: cleanup temporary audio files after transcription to prevent storage buildup#27
dhruvi-16-me wants to merge 1 commit intoAOSSIE-Org:mainfrom
dhruvi-16-me:cleanup-audio-files

Conversation

@dhruvi-16-me
Copy link
Copy Markdown

@dhruvi-16-me dhruvi-16-me commented Mar 23, 2026

Closes #19

📝 Description

This PR addresses the issue of temporary audio files not being deleted after transcription. Currently, each consultation recording is stored in the temporary directory but never cleaned up, leading to potential storage accumulation over time.

The solution ensures that recorded audio files are deleted after every transcription attempt, regardless of whether the process succeeds, fails, or exits early. This is achieved using a try/finally pattern to guarantee cleanup across all execution paths.

Additionally, the implementation safely handles file deletion to avoid impacting the user experience.

🔧 Changes Made

  • Updated _transcribeAudio() in lib/main.dart to:

    • Store _recordingPath in a local variable to prevent race conditions
    • Wrap transcription logic inside a try/finally block to ensure cleanup
  • Added _deleteRecordingFile(String path) helper method:

    • Safely deletes the file if it exists
    • Handles errors gracefully without affecting app flow
  • Ensured _recordingPath is cleared after cleanup (when applicable)

  • Covered all execution paths:

    • Successful transcription
    • API failure
    • Early return (missing file)
    • Exceptions

📷 Screenshots or Visual Changes (if applicable)

No visual changes. This PR focuses on internal resource cleanup and performance improvement.

🤝 Collaboration

Collaborated with: N/A

✅ Checklist

  • I have read the contributing guidelines.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if applicable).
  • Any dependent changes have been merged and published in downstream modules.
  • I have joined the [Discord server](https://discord.gg/hjUhu33uAn) and I will share a link to this PR with the project maintainers there

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • Bug Fixes
    • Improved transcription workflow reliability with enhanced cleanup of temporary recording files after completion, preventing potential storage issues and ensuring more stable app operation.

@github-actions
Copy link
Copy Markdown

⚠️ This PR has merge conflicts.

Please resolve the merge conflicts before review.

Your PR will only be reviewed by a maintainer after all conflicts have been resolved.

📺 Watch this video to understand why conflicts occur and how to resolve them:
https://www.youtube.com/watch?v=Sqsz1-o7nXk

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 18ca76d8-5159-4800-9674-84dc26c79cc4

📥 Commits

Reviewing files that changed from the base of the PR and between 3f66d62 and 89b5e7c.

📒 Files selected for processing (1)
  • lib/main.dart

📝 Walkthrough

Walkthrough

The transcription workflow now captures the recording path into a local variable and adds a finally block to guarantee cleanup of temporary audio files. A new helper method deletes the recording file with existence verification, error handling, and logging, then conditionally clears the path reference.

Changes

Cohort / File(s) Summary
Temporary File Cleanup
lib/main.dart
Added _deleteRecordingFile() helper method with existence checks, error handling, and logging. Modified _transcribeAudio() to snapshot _recordingPath, construct File from snapshot, and execute file deletion in finally block with conditional path clearing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Whiskers twitching with delight,
Audio files cleaned up tight,
No more clutter on the phone,
Every temp file finds its home!
Storage singing, storage free,
Cleanup code as it should be! 🗑️✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding cleanup of temporary audio files after transcription to prevent storage buildup.
Linked Issues check ✅ Passed The pull request implements all coding requirements from issue #19: adding file deletion logic in _transcribeAudio() with proper error handling and cleanup in all code paths.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the cleanup functionality specified in issue #19; no extraneous modifications were introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Important

Merge conflicts detected (Beta)

  • Resolve merge conflict in branch cleanup-audio-files
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size/S and removed size/S labels Mar 23, 2026
@SharkyBytes
Copy link
Copy Markdown
Contributor

LGTM! resolve the merge conflixts

@dhruvi-16-me
Copy link
Copy Markdown
Author

@SharkyBytes Will fix this PR today. Last night left it in between.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Clean Up Temporary Audio Files After Transcription

2 participants