• 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_speachessrcspeachesaudio.py
Download as .zip file
File name
Commit message
Commit date
.github/workflows
feat: switch to ghcr.io
01-10
configuration
feat: add instrumentation
2024-12-17
docs
rename to `speaches`
01-12
examples
rename to `speaches`
01-12
scripts
chore: misc changes
2024-10-03
src/speaches
rename to `speaches`
01-12
tests
rename to `speaches`
01-12
.dockerignore
chore: update .dockerignore
2024-11-01
.envrc
init
2024-05-20
.gitattributes
chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.7.2
2024-11-02
.gitignore
chore: update .gitignore
2024-07-03
.pre-commit-config.yaml
chore(deps): update pre-commit hook detachhead/basedpyright-pre-commit-mirror to v1.23.2
01-12
Dockerfile
chore(deps): update ghcr.io/astral-sh/uv docker tag to v0.5.18
01-12
LICENSE
init
2024-05-20
README.md
rename to `speaches`
01-12
Taskfile.yaml
rename to `speaches`
01-12
audio.wav
chore: update volume names and mount points
01-10
compose.cpu.yaml
rename to `speaches`
01-12
compose.cuda-cdi.yaml
rename to `speaches`
01-12
compose.cuda.yaml
rename to `speaches`
01-12
compose.observability.yaml
rename to `speaches`
01-12
compose.yaml
rename to `speaches`
01-12
flake.lock
deps: update flake
2024-11-01
flake.nix
chore(deps): add loki and tempo package to flake
2024-12-17
mkdocs.yml
rename to `speaches`
01-12
pyproject.toml
rename to `speaches`
01-12
renovate.json
feat: renovate handle pre-commit
2024-11-01
uv.lock
rename to `speaches`
01-12
File name
Commit message
Commit date
routers
rename to `speaches`
01-12
__init__.py
rename to `speaches`
01-12
api_models.py
rename to `speaches`
01-12
asr.py
rename to `speaches`
01-12
audio.py
rename to `speaches`
01-12
config.py
rename to `speaches`
01-12
dependencies.py
rename to `speaches`
01-12
gradio_app.py
rename to `speaches`
01-12
hf_utils.py
rename to `speaches`
01-12
logger.py
rename to `speaches`
01-12
main.py
rename to `speaches`
01-12
model_manager.py
rename to `speaches`
01-12
text_utils.py
rename to `speaches`
01-12
text_utils_test.py
rename to `speaches`
01-12
transcriber.py
rename to `speaches`
01-12
Fedir Zadniprovskyi 01-12 0cffb52 rename to `speaches` UNIX
Raw Open in browser Change history
from __future__ import annotations import asyncio import logging from typing import TYPE_CHECKING, BinaryIO import numpy as np import soundfile as sf from speaches.config import SAMPLES_PER_SECOND if TYPE_CHECKING: from collections.abc import AsyncGenerator from numpy.typing import NDArray logger = logging.getLogger(__name__) 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: if self.duration > i: yield self.after(i).data return if 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

          
        
    
    
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