Skip to content

refactor: extract Deepgram API call into TranscriptionService#17

Closed
SISIR-REDDY wants to merge 1 commit intoAOSSIE-Org:mainfrom
SISIR-REDDY:refactor/extract-transcription-service
Closed

refactor: extract Deepgram API call into TranscriptionService#17
SISIR-REDDY wants to merge 1 commit intoAOSSIE-Org:mainfrom
SISIR-REDDY:refactor/extract-transcription-service

Conversation

@SISIR-REDDY
Copy link

Closes #11

Problem

As noted in #11, main.dart was doing too many things at once — managing UI state, handling audio recording, making raw Deepgram HTTP requests, and orchestrating Gemini processing, all in a single 500-line file. This made the Deepgram logic untestable in isolation and harder to change without touching the UI.

Changes

lib/services/transcription_service.dart (new file)

TranscriptionService takes sole ownership of the Deepgram integration:

  • transcribe(filePath) handles reading the file, POSTing to the Deepgram Nova-2 endpoint, parsing the response, and mapping errors to human-readable messages.
  • Returns a TranscriptionResult value object (success / failure) so the caller never has to inspect HTTP status codes.
  • hasValidApiKey rejects empty and placeholder key values before any network call is made.
  • Timeout set to 60 seconds to handle large audio files.
  • All logging goes through developer.log() with the TranscriptionService tag.

lib/main.dart

  • _TranscriptionScreenState now instantiates TranscriptionService alongside ChatbotService.
  • _transcribeAudio() is reduced from ~50 lines of HTTP boilerplate to a single await _transcriptionService.transcribe(_recordingPath) call followed by straightforward state updates based on result.isSuccess.
  • Removed now-unused imports: dart:convert, dart:io, package:http/http.dart, package:flutter_markdown/flutter_markdown.dart.

What was intentionally left for follow-up

The audio recording logic (_startRecording, _stopRecording, AudioRecorder) still lives in the widget. Extracting that is a larger change — a RecordingService would be a natural next step, but keeping this PR focused makes it easier to review.

Closes AOSSIE-Org#11

main.dart previously mixed UI state, audio recording, Deepgram HTTP
calls, and Gemini processing in a single 500-line file. This commit
starts separating those concerns by pulling the Deepgram integration
into its own service class.

- Add lib/services/transcription_service.dart
  TranscriptionService owns the Deepgram HTTP call, timeout, and
  response parsing. Introduces TranscriptionResult (success/failure)
  so callers do not need to parse raw HTTP status codes.
  hasValidApiKey rejects empty and placeholder values.
  All logging goes through developer.log() with a named tag.

- Update lib/main.dart
  Instantiate TranscriptionService alongside ChatbotService.
  Replace the inline _transcribeAudio() HTTP block with a single
  call to _transcriptionService.transcribe().
  Remove now-unused imports: dart:convert, dart:io, package:http,
  package:flutter_markdown.
@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

Warning

Rate limit exceeded

@SISIR-REDDY has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 41 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6784dc91-b833-4a08-a957-c052fb44e18e

📥 Commits

Reviewing files that changed from the base of the PR and between ece30ed and d29b2ea.

📒 Files selected for processing (2)
  • lib/main.dart
  • lib/services/transcription_service.dart
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@hasanravda
Copy link
Contributor

I have already did the changes in PR#12 , please refer it !
@SISIR-REDDY

@github-actions
Copy link

⚠️ 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

@dhruvi-16-me
Copy link

dhruvi-16-me commented Mar 23, 2026

Hey @SharkyBytes This PR is not needed anymore. This was handled in PR #12. This is a duplicate PR. Since this is not needed I am closing it.

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]: Refactor TranscriptionScreen to Follow Separation of Concerns and Improve Maintainability

3 participants