• Y
  • List All
  • Feedback
    • This Project
    • All Projects
Profile Account settings Log out
  • Favorite
  • Project
  • All
Loading...
  • Log in
  • Sign up
yjyoon / whisper_server_speaches star
  • Project homeH
  • CodeC
  • IssueI
  • Pull requestP
  • Review R
  • MilestoneM
  • BoardB
  • Files
  • Commit
  • Branches
whisper_server_speachesfaster_whisper_serveraudio.py
Download as .zip file
File name
Commit message
Commit date
.github/workflows
update pre-commit deps, replace custom pyright hook
2024-07-03
examples
chore: update docker tag to latest
2024-06-03
faster_whisper_server
chore: fix ruff errors
2024-07-03
tests
chore: fix ruff errors
2024-07-03
.dockerignore
chore: ignore .env
2024-05-27
.envrc
init
2024-05-20
.gitattributes
docs: add live-transcription demo
2024-05-28
.gitignore
chore: update .gitignore
2024-07-03
.pre-commit-config.yaml
update pre-commit deps, replace custom pyright hook
2024-07-03
Dockerfile.cpu
fix task enum vals, fix env var parsing, improve gradio, use uv in dockerfile
2024-06-23
Dockerfile.cuda
fix task enum vals, fix env var parsing, improve gradio, use uv in dockerfile
2024-06-23
LICENSE
init
2024-05-20
README.md
Update README.md
2024-06-26
Taskfile.yaml
switch to using uv
2024-07-03
audio.wav
docs: update README.md
2024-05-27
compose.yaml
chore: update docker tag to latest
2024-06-03
flake.lock
init
2024-05-20
flake.nix
switch to using uv
2024-07-03
lsyncd.conf
chore: add lsyncd config
2024-06-03
pyproject.toml
chore: fix ruff errors
2024-07-03
requirements-all.txt
switch to using uv
2024-07-03
requirements-dev.txt
switch to using uv
2024-07-03
requirements.txt
switch to using uv
2024-07-03
File name
Commit message
Commit date
__init__.py
chore: rename to 'faster-whisper-server'
2024-05-27
asr.py
chore: fix ruff errors
2024-07-03
audio.py
chore: fix ruff errors
2024-07-03
config.py
chore: fix ruff errors
2024-07-03
core.py
chore: fix ruff errors
2024-07-03
gradio_app.py
chore: fix ruff errors
2024-07-03
logger.py
chore: fix ruff errors
2024-07-03
main.py
chore: fix ruff errors
2024-07-03
server_models.py
chore: fix ruff errors
2024-07-03
transcriber.py
chore: fix ruff errors
2024-07-03
utils.py
chore: rename to 'faster-whisper-server'
2024-05-27
Fedir Zadniprovskyi 2024-07-03 88f0467 chore: fix ruff errors UNIX
Raw Open in browser Change history
from __future__ import annotations import asyncio from typing import TYPE_CHECKING, BinaryIO import numpy as np import soundfile as sf from faster_whisper_server.config import SAMPLES_PER_SECOND from faster_whisper_server.logger import logger if TYPE_CHECKING: from collections.abc import AsyncGenerator from numpy.typing import NDArray def audio_samples_from_file(file: BinaryIO) -> NDArray[np.float32]: audio_and_sample_rate = sf.read( file, format="RAW", channels=1, samplerate=SAMPLES_PER_SECOND, subtype="PCM_16", dtype="float32", endian="LITTLE", ) audio = audio_and_sample_rate[0] return audio # pyright: ignore[reportReturnType] class Audio: def __init__( self, data: NDArray[np.float32] = np.array([], dtype=np.float32), start: float = 0.0, ) -> None: self.data = data self.start = start def __repr__(self) -> str: return f"Audio(start={self.start:.2f}, end={self.end:.2f})" @property def end(self) -> float: return self.start + self.duration @property def duration(self) -> float: return len(self.data) / SAMPLES_PER_SECOND def after(self, ts: float) -> Audio: assert ts <= self.duration return Audio(self.data[int(ts * SAMPLES_PER_SECOND) :], start=ts) def extend(self, data: NDArray[np.float32]) -> None: # logger.debug(f"Extending audio by {len(data) / SAMPLES_PER_SECOND:.2f}s") self.data = np.append(self.data, data) # logger.debug(f"Audio duration: {self.duration:.2f}s") # TODO: trim data longer than x class AudioStream(Audio): def __init__( self, data: NDArray[np.float32] = np.array([], dtype=np.float32), start: float = 0.0, ) -> None: super().__init__(data, start) self.closed = False self.modify_event = asyncio.Event() def extend(self, data: NDArray[np.float32]) -> None: assert not self.closed super().extend(data) self.modify_event.set() def close(self) -> None: assert not self.closed self.closed = True self.modify_event.set() logger.info("AudioStream closed") async def chunks(self, min_duration: float) -> AsyncGenerator[NDArray[np.float32], None]: i = 0.0 # end time of last chunk while True: await self.modify_event.wait() self.modify_event.clear() if self.closed or self.duration - i >= min_duration: # If `i` shouldn't be set to `duration` after the yield # because by the time assignment would happen more data might have been added i_ = i i = self.duration # NOTE: probably better to just to a slice yield self.after(i_).data if self.closed: return

          
        
    
    
Copyright Yona authors & © NAVER Corp. & NAVER LABS Supported by NAVER CLOUD PLATFORM

or
Sign in with github login with Google Sign in with Google
Reset password | Sign up