Skip to content

Commit

Permalink
Fix float sample rate (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams authored Oct 6, 2022
1 parent 1caad5f commit 2213c92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- run: poetry install
- name: Test
run: poetry run pytest --cov --cov-fail-under=73
run: poetry run make test
build:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ clean:
rm -r dist/* || true

test:
pytest --cov --cov-fail-under=75
pytest --cov --cov-fail-under=73

bundle_mac:
make buzz
Expand Down
9 changes: 7 additions & 2 deletions transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ def process_queue(self):
continue

def get_device_sample_rate(self, device_id: Optional[int]) -> int:
"""Returns the sample rate to be used for recording. It uses the default sample rate
provided by Whisper if the microphone supports it, or else it uses the device's default
sample rate.
"""
whisper_sample_rate = whisper.audio.SAMPLE_RATE
try:
sounddevice.check_input_settings(
device=device_id, samplerate=whisper_sample_rate)
return whisper_sample_rate
except:
device_info = sounddevice.query_devices(device=device_id)
return device_info.get( # type: ignore
'default_samplerate', whisper_sample_rate)
if isinstance(device_info, dict):
return int(device_info.get('default_samplerate', whisper_sample_rate))
return whisper_sample_rate

def stream_callback(self, in_data, frame_count, time_info, status):
# Try to enqueue the next block. If the queue is already full, drop the block.
Expand Down

0 comments on commit 2213c92

Please sign in to comment.