Skip to content

Conversation

@ftnext
Copy link
Collaborator

@ftnext ftnext commented Mar 23, 2025

Delete boilerplate code as refactoring first step

@ftnext ftnext requested a review from Copilot March 23, 2025 08:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors audio file processing to eliminate repetitive boilerplate code by introducing the class method AudioData.from_file(), simplifying how audio files are loaded across the codebase.

  • Extracts common audio file loading logic into AudioData.from_file() in speech_recognition/audio.py.
  • Replaces duplicate code that creates a Recognizer, opens an AudioFile, and records audio with a single, convenient method call.
  • Updates examples, recognizers, and tests to use the new from_file() method.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
examples/audio_transcribe.py Updated to load audio using AudioData.from_file().
examples/extended_results.py Updated to use the new from_file() for audio loading.
speech_recognition/recognizers/whisper_local/faster_whisper.py Replaced r.listen with from_file() call for file-based audio loading.
examples/special_recognizer_features.py Updated to load audio using the new from_file() method.
speech_recognition/audio.py Introduces the new AudioData.from_file() class method.
speech_recognition/recognizers/whisper_api/openai.py Switched to using from_file() instead of r.listen for audio input.
tests/test_recognition.py Updated tests to load audio using the new from_file() method.
tests/test_special_features.py Changed to use from_file() for improved consistency.
tests/test_audio.py Replaced boilerplate audio loading with the from_file() method.
Comments suppressed due to low confidence (2)

speech_recognition/recognizers/whisper_local/faster_whisper.py:101

  • Replacing r.listen with sr.AudioData.from_file changes the behavior from using r.listen to using r.record internally. Confirm that this change is intentional since it may alter how the audio data is captured.
audio_data = sr.AudioData.from_file(args.audio_file)

speech_recognition/recognizers/whisper_api/openai.py:73

  • Switching from r.listen to sr.AudioData.from_file (which uses r.record) could change the audio capture behavior. Verify that this behavior change aligns with the intended functionality for file-based audio input.
audio_data = sr.AudioData.from_file(args.audio_file)

@ftnext ftnext merged commit b43441c into Uberi:master Mar 24, 2025
8 checks passed
@ftnext ftnext deleted the refactor/audiodata-factory-method branch March 24, 2025 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant