• 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_speachesspeachesaudio.py
Download as .zip file
File name
Commit message
Commit date
speaches
chore: Dockerfile envs, log ws close, etc.
2024-05-20
tests
init
2024-05-20
.dockerignore
init
2024-05-20
.envrc
init
2024-05-20
.gitignore
init
2024-05-20
.pre-commit-config.yaml
init
2024-05-20
Dockerfile.cpu
chore: Dockerfile envs, log ws close, etc.
2024-05-20
Dockerfile.cuda
chore: Dockerfile envs, log ws close, etc.
2024-05-20
LICENSE
init
2024-05-20
README.md
docs: add WIP warning
2024-05-20
Taskfile.yaml
chore: Dockerfile envs, log ws close, etc.
2024-05-20
compose.yaml
init
2024-05-20
flake.lock
init
2024-05-20
flake.nix
init
2024-05-20
poetry.lock
init
2024-05-20
pyproject.toml
init
2024-05-20
File name
Commit message
Commit date
__init__.py
init
2024-05-20
asr.py
init
2024-05-20
audio.py
init
2024-05-20
config.py
chore: Dockerfile envs, log ws close, etc.
2024-05-20
core.py
init
2024-05-20
logger.py
init
2024-05-20
main.py
chore: Dockerfile envs, log ws close, etc.
2024-05-20
server_models.py
init
2024-05-20
transcriber.py
init
2024-05-20
Fedir Zadniprovskyi 2024-05-20 8ad3023 init UNIX
Raw Open in browser Change history
from __future__ import annotations import asyncio from typing import AsyncGenerator, BinaryIO import numpy as np import soundfile as sf from numpy.typing import NDArray from speaches.config import SAMPLES_PER_SECOND from speaches.logger import logger def audio_samples_from_file(file: BinaryIO) -> NDArray[np.float32]: audio_and_sample_rate: tuple[NDArray[np.float32], Any] = sf.read( # type: ignore file, format="RAW", channels=1, samplerate=SAMPLES_PER_SECOND, subtype="PCM_16", dtype="float32", endian="LITTLE", ) audio = audio_and_sample_rate[0] return audio 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 self.closed == False super().extend(data) self.modify_event.set() def close(self) -> None: assert self.closed == False 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