Unverified Commit d54d7598 authored by Nicolas Patry's avatar Nicolas Patry Committed by GitHub
Browse files

Microphone live inference catching up when inference is too slow (whisper). (#21219)

* Microphone live inference catching up when inference is too slow
(whisper).

* Adding copyright.
parent 7fc1cb15
# Copyright 2023 The HuggingFace Team. All rights reserved.
import datetime
import platform
import subprocess
from typing import Optional, Tuple, Union
......@@ -154,6 +156,8 @@ def ffmpeg_microphone_live(
stride_left = int(round(sampling_rate * stride_length_s[0])) * size_of_sample
stride_right = int(round(sampling_rate * stride_length_s[1])) * size_of_sample
audio_time = datetime.datetime.now()
delta = datetime.timedelta(seconds=chunk_s)
for item in chunk_bytes_iter(microphone, chunk_len, stride=(stride_left, stride_right), stream=True):
# Put everything back in numpy scale
item["raw"] = np.frombuffer(item["raw"], dtype=dtype)
......@@ -162,6 +166,10 @@ def ffmpeg_microphone_live(
item["stride"][1] // size_of_sample,
)
item["sampling_rate"] = sampling_rate
audio_time += delta
if datetime.datetime.now() > audio_time + 10 * delta:
# We're late !! SKIP
continue
yield item
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment