Instructions to use MoYoYoTech/Translator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use MoYoYoTech/Translator with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf MoYoYoTech/Translator:Q5_0 # Run inference directly in the terminal: llama cli -hf MoYoYoTech/Translator:Q5_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf MoYoYoTech/Translator:Q5_0 # Run inference directly in the terminal: llama cli -hf MoYoYoTech/Translator:Q5_0
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf MoYoYoTech/Translator:Q5_0 # Run inference directly in the terminal: ./build/bin/llama cli -hf MoYoYoTech/Translator:Q5_0
Use Docker
docker model run hf.co/MoYoYoTech/Translator:Q5_0
- Llama new
- LM Studio
- Jan
- Ollama
How to use MoYoYoTech/Translator with Ollama:
ollama run hf.co/MoYoYoTech/Translator:Q5_0
- Unsloth Desktop
- Pi
How to use MoYoYoTech/Translator with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf MoYoYoTech/Translator:Q5_0
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:9931/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "MoYoYoTech/Translator:Q5_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use MoYoYoTech/Translator with Docker Model Runner:
docker model run hf.co/MoYoYoTech/Translator:Q5_0
- Lemonade
How to use MoYoYoTech/Translator with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull MoYoYoTech/Translator:Q5_0
Run and chat with the model
lemonade run user.Translator-Q5_0
List all available models
lemonade list
- Hermes Agent
How to use MoYoYoTech/Translator with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf MoYoYoTech/Translator:Q5_0
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:9931/v1 hermes config set model.default MoYoYoTech/Translator:Q5_0
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use MoYoYoTech/Translator with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf MoYoYoTech/Translator:Q5_0
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:9931/v1 \ --custom-model-id "MoYoYoTech/Translator:Q5_0" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
daihui.zhang commited on
Commit ·
4d568e6
1
Parent(s): 9ce0bfb
update add fix
Browse filesFiles changed (20)
- .gitignore+1-1
- main.pyAdded
- moyoyo_asr_models/Qwen2.5-3B.Q5_0.ggufAdded+3
- moyoyo_asr_models/qwen2.5-7b-instruct-q5_0-00001-of-00002.ggufAdded+3
- moyoyo_asr_models/qwen2.5-7b-instruct-q5_0-00002-of-00002.ggufAdded+3
- pyproject.toml+3
- requirements.txt+31-23
- transcribe/helpers/__init__.pyAdded
- transcribe/translator.py → transcribe/helpers/translator.pyRenamed
- transcribe/helpers/vadprocessor.pyAdded+251
- transcribe/whisper.py → transcribe/helpers/whisper.pyRenamed
- transcribe/pipelines/__init__.py+1
- transcribe/pipelines/base.py+1
- transcribe/pipelines/pipe_translate.py+1-1
- transcribe/pipelines/pipe_vad.py+68-1
- transcribe/pipelines/pipe_whisper.py+1-1
- transcribe/translatepipes.py+19-10
- transcribe/utils.py+6
- transcribe/whisper_llm_serve.py+50-22
- uv.lock+100
67 unmodified lines686970717172737467 unmodified lines
# Sphinx documentationdocs/_build/
test/# PyBuilder.pybuilder/target/123version https://git-lfs.github.com/spec/v1oid sha256:35a1eec88348fd963b06bb2e3ba8d4d27d4f7a79d9ed4bab645f931d7b2b7ac7size 2169666016123version https://git-lfs.github.com/spec/v1oid sha256:715a0c76b1b074ed65fe0fabf88b1df6f5f638318f15ba9f62a04d493e236d5fsize 4001112160123version https://git-lfs.github.com/spec/v1oid sha256:6a254c888ebffcddf98b0c277433a339d9a8cbf970f246b0b6e6a9195e5d6cfbsize 13140644165 unmodified lines678910111213141516171819205 unmodified linesrequires-python = ">=3.11"dependencies = [ "av>=14.2.0", "fastapi>=0.115.12", "librosa>=0.11.0", "numpy>=2.1.3", "onnxruntime>=1.21.0", "pyaudio>=0.2.14", "pydantic>=2.11.2", "pydub>=0.25.1", "setuptools>=78.1.0", "silero-vad>=5.1.2", "soundfile>=0.13.1", "torch>=2.6.0", "tqdm>=4.67.1",1 unmodified line234567898 unmodified lines181920192021222324253 unmodified lines2930313031323334333435363738392 unmodified lines424344434445464710 unmodified lines58596061616264636465666768706970717273747576777879777879803 unmodified lines84858687898889909192929394959697959697982 unmodified lines1011021031041051061071081091101111121131141151161171181 unmodified line1201211221191201231241231251261271281291301311321331341351271361371381 unmodified line# uv pip compile pyproject.toml -o requirements.txtannotated-types==0.7.0 # via pydanticanyio==4.9.0 # via starletteaudioread==3.0.1 # via librosaav==14.3.08 unmodified lines # via onnxruntimedecorator==5.2.1 # via librosadiskcache==5.6.3 # via llama-cpp-pythonfastapi==0.115.12 # via trans (pyproject.toml)filelock==3.18.0 # via torchflatbuffers==25.2.103 unmodified lineshumanfriendly==10.0 # via coloredlogsidna==3.10 # via requestsjinja2==3.1.6 # via # llama-cpp-python # torch # anyio # requestsjinja2==3.1.6 # via torchjoblib==1.4.2 # via # librosa2 unmodified lines # via librosalibrosa==0.11.0 # via trans (pyproject.toml)llama-cpp-python==0.3.8 # via trans (pyproject.toml)llvmlite==0.44.0 # via numbamarkupsafe==3.0.210 unmodified lines # via # trans (pyproject.toml) # librosa # llama-cpp-python # numba # onnxruntime # pywhispercpp # scikit-learn # scipy # soundfile # soxronnxruntime==1.21.0 # via # via trans (pyproject.toml) # trans (pyproject.toml) # silero-vadpackaging==24.2 # via # lazy-loader # onnxruntime # poochplatformdirs==4.3.7 # via # pooch # pywhispercpp # via poochpooch==1.8.2 # via librosaprotobuf==6.30.23 unmodified linespycparser==2.22 # via cffipydantic==2.11.2 # via # via trans (pyproject.toml) # trans (pyproject.toml) # fastapipydantic-core==2.33.1 # via pydanticpywhispercpp==1.3.0pydub==0.25.1 # via trans (pyproject.toml)requests==2.32.3 # via # pooch # pywhispercpp # via poochscikit-learn==1.6.1 # via librosascipy==1.15.22 unmodified lines # scikit-learnsetuptools==78.1.0 # via trans (pyproject.toml)silero-vad==5.1.2 # via trans (pyproject.toml)sniffio==1.3.1 # via anyiosoundfile==0.13.1 # via # trans (pyproject.toml) # librosasoxr==0.5.0.post1 # via librosastarlette==0.46.1 # via fastapisympy==1.13.1 # via # onnxruntime1 unmodified linethreadpoolctl==3.6.0 # via scikit-learntorch==2.6.0 # via trans (pyproject.toml)tqdm==4.67.1 # via # trans (pyproject.toml) # pywhispercpp # silero-vad # torchaudiotorchaudio==2.6.0 # via silero-vadtqdm==4.67.1 # via trans (pyproject.toml)typing-extensions==4.13.1 # via # anyio # fastapi # librosa # llama-cpp-python # pydantic # pydantic-core # torch123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251import gcimport timeimport numpy as npimport onnxruntimefrom datetime import timedeltafrom pydub import AudioSegmentfrom silero_vad import load_silero_vad, get_speech_timestampsimport osimport logging
class SileroVADProcessor: """ A class for processing audio files using Silero VAD to detect voice activity and extract voice segments from audio files. """
def __init__(self, activate_threshold=0.5, fusion_threshold=0.3, min_speech_duration=0.25, max_speech_duration=20, min_silence_duration=250, sample_rate=16000, ort_providers=None): """ Initialize the SileroVADProcessor.
Args: activate_threshold (float): Threshold for voice activity detection fusion_threshold (float): Threshold for merging close speech segments (seconds) min_speech_duration (float): Minimum duration of speech to be considered valid (seconds) max_speech_duration (float): Maximum duration of speech (seconds) min_silence_duration (int): Minimum silence duration (ms) sample_rate (int): Sample rate of the audio (8000 or 16000 Hz) ort_providers (list): ONNX Runtime providers for acceleration """ # VAD parameters self.activate_threshold = activate_threshold self.fusion_threshold = fusion_threshold self.min_speech_duration = min_speech_duration self.max_speech_duration = max_speech_duration self.min_silence_duration = min_silence_duration self.sample_rate = sample_rate self.ort_providers = ort_providers if ort_providers else []
# Initialize logger self.logger = logging.getLogger(__name__)
# Load Silero VAD model self._init_onnx_session() self.silero_vad = load_silero_vad(onnx=True)
def _init_onnx_session(self): """Initialize ONNX Runtime session with appropriate settings.""" session_opts = onnxruntime.SessionOptions() session_opts.log_severity_level = 3 session_opts.inter_op_num_threads = 0 session_opts.intra_op_num_threads = 0 session_opts.enable_cpu_mem_arena = True session_opts.execution_mode = onnxruntime.ExecutionMode.ORT_SEQUENTIAL session_opts.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL
session_opts.add_session_config_entry("session.intra_op.allow_spinning", "1") session_opts.add_session_config_entry("session.inter_op.allow_spinning", "1") session_opts.add_session_config_entry("session.set_denormal_as_zero", "1")
# Set the session_opts to be used by silero_vad # onnxruntime.capi._pybind_state.get_default_session_options(session_opts)
def load_audio(self, audio_path): """ Load audio file and prepare it for VAD processing.
Args: audio_path (str): Path to the audio file
Returns: numpy.ndarray: Audio data as numpy array """ self.logger.info(f"Loading audio from {audio_path}") audio_segment = AudioSegment.from_file(audio_path) audio_segment = audio_segment.set_channels(1).set_frame_rate(self.sample_rate)
# Convert to numpy array and normalize dtype = np.float16 if self.use_gpu_fp16 else np.float32 audio_array = np.array(audio_segment.get_array_of_samples(), dtype=dtype) * 0.000030517578 # 1/32768
self.audio_segment = audio_segment # Store for later use return audio_array @property def model(self): return self.silero_vad
def process_timestamps(self, timestamps): """ Process VAD timestamps: filter short segments and merge close segments.
Args: timestamps (list): List of (start, end) tuples
Returns: list: Processed list of (start, end) tuples """ # Filter out short durations filtered_timestamps = [(start, end) for start, end in timestamps if (end - start) >= self.min_speech_duration]
# Fuse timestamps in two passes for better merging fused_timestamps_1st = [] for start, end in filtered_timestamps: if fused_timestamps_1st and (start - fused_timestamps_1st[-1][1] <= self.fusion_threshold): fused_timestamps_1st[-1] = (fused_timestamps_1st[-1][0], end) else: fused_timestamps_1st.append((start, end))
fused_timestamps_2nd = [] for start, end in fused_timestamps_1st: if fused_timestamps_2nd and (start - fused_timestamps_2nd[-1][1] <= self.fusion_threshold): fused_timestamps_2nd[-1] = (fused_timestamps_2nd[-1][0], end) else: fused_timestamps_2nd.append((start, end))
return fused_timestamps_2nd
def format_time(self, seconds): """ Convert seconds to VTT time format 'hh:mm:ss.mmm'.
Args: seconds (float): Time in seconds
Returns: str: Formatted time string """ td = timedelta(seconds=seconds) td_sec = td.total_seconds() total_seconds = int(td_sec) milliseconds = int((td_sec - total_seconds) * 1000) hours = total_seconds // 3600 minutes = (total_seconds % 3600) // 60 seconds = total_seconds % 60 return f"{hours:02}:{minutes:02}:{seconds:02}.{milliseconds:03}"
def detect_speech(self, audio:np.array): """ Run VAD on the audio file to detect speech segments.
Args: audio_path (str): Path to the audio file
Returns: list: List of processed timestamps as (start, end) tuples """ self.logger.info("Starting VAD process") start_time = time.time() # Get speech timestamps raw_timestamps = get_speech_timestamps( audio, model=self.silero_vad, threshold=self.activate_threshold, max_speech_duration_s=self.max_speech_duration, min_speech_duration_ms=int(self.min_speech_duration * 1000), min_silence_duration_ms=self.min_silence_duration, return_seconds=True )
# Convert to simple format and process timestamps = [(item['start'], item['end']) for item in raw_timestamps] processed_timestamps = self.process_timestamps(timestamps)
# Clean up del audio gc.collect()
self.logger.info(f"VAD completed in {time.time() - start_time:.3f} seconds") return processed_timestamps
""" Save timestamps in both second and sample indices formats.
Args: timestamps (list): List of (start, end) tuples output_prefix (str): Prefix for output files """ # Save timestamps in seconds (VTT format) seconds_path = f"{output_prefix}_timestamps_second.txt" with open(seconds_path, "w", encoding='UTF-8') as file: self.logger.info("Saving timestamps in seconds format") for start, end in timestamps: s_time = self.format_time(start) e_time = self.format_time(end) line = f"{s_time} --> {e_time}\n" file.write(line)
# Save timestamps in sample indices indices_path = f"{output_prefix}_timestamps_indices.txt" with open(indices_path, "w", encoding='UTF-8') as file: self.logger.info("Saving timestamps in indices format") for start, end in timestamps: line = f"{int(start * self.sample_rate)} --> {int(end * self.sample_rate)}\n" file.write(line)
self.logger.info(f"Timestamps saved to {seconds_path} and {indices_path}")
def extract_speech_segments(self, audio_segment, timestamps): """ Extract speech segments from the audio and combine them into a single audio file.
Args: timestamps (list): List of (start, end) tuples indicating speech segments
Returns: AudioSegment: The combined speech segments """ audio_segment = audio_segment.numpy() combined_speech = np.array([], dtype=np.float32)
# Extract and combine each speech segment for i, (start, end) in enumerate(timestamps): # Convert seconds to milliseconds for pydub start_ms = int(start * 1000) end_ms = int(end * 1000)
# Ensure the end time does not exceed the length of the audio segment if end_ms > len(audio_segment): end_ms = len(audio_segment)
# Extract the segment segment = audio_segment[start_ms:end_ms]
# Add to combined audio combined_speech = np.append(combined_speech, segment)
return combined_speech
def process_audio(self, audio_array:np.array): """ Complete processing pipeline: detect speech, save timestamps, and optionally extract speech.
Returns: tuple: (timestamps, output_speech_path if extract_speech else None) """
# Run VAD to detect speech timestamps = self.detect_speech(audio_array)
combined_speech = self.extract_speech_segments(audio_array, timestamps)
return timestamps, combined_speech12345
from .pipe_translate import TranslatePipefrom .pipe_whisper import WhisperPipefrom .pipe_vad import VadPipefrom .base import MetaItem11 unmodified lines1213141516171811 unmodified lines@dataclassclass MetaItem: segments: list[Segment] = field(default_factory=list) source_audio: bytes = b"" audio: bytes = b'' transcribe_content: str = '' translate_content: str = ''12344567
from .base import MetaItem, BasePipe, Segmentfrom llama_cpp import Llamafrom ..translator import QwenTranslatorfrom ..helpers.translator import QwenTranslatorfrom config import LLM_MODEL_PATH, LLM_SYS_PROMPT
122345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
from .base import MetaItem, BasePipefrom ..helpers.vadprocessor import SileroVADProcessorimport numpy as npfrom silero_vad import read_audio, get_speech_timestamps,collect_chunks, VADIteratorimport torch
class VadPipe(BasePipe): model = None sample_rate=16000 window_size_samples = 512
@classmethod def init(cls): if cls.model is None: cls.model = SileroVADProcessor( activate_threshold=0.5, fusion_threshold=0.3, min_speech_duration=0.25, max_speech_duration=20, min_silence_duration=250, sample_rate=cls.sample_rate )
@property def vad_iterator(self): return VADIterator(self.model.silero_vad, sampling_rate=self.sample_rate,)
def process(self, in_data: MetaItem) -> MetaItem: source_audio = in_data.source_audio source_audio = np.frombuffer(source_audio, dtype=np.float32) speech_segments = [] is_speech_active = False # current_segment_end = len(source_audio) for i in range(0, len(source_audio), self.window_size_samples):
window = source_audio[i:i+self.window_size_samples] if len(window) < self.window_size_samples: padded_window = np.zeros(self.window_size_samples, dtype=np.float32) padded_window[:len(window)] = window window = padded_window
speech_dict = self.vad_iterator(window, return_seconds=False) if not speech_dict: continue # 计算当前偏移量
if speech_dict and 'start' in speech_dict and not is_speech_active: is_speech_active = True # current_segment_start = speech_dict['start'] + i if is_speech_active: speech_segments.append(window) # # 如果检测到语音结束 # if speech_dict and 'end' in speech_dict and is_speech_active: # # 调整语音结束时间,加上窗口偏移 # current_segment_end = min(speech_dict['end'] + i, current_segment_end) # is_speech_active = False # speech_audio = source_audio[current_segment_start: current_segment_end] # speech_segments.append(speech_audio)
self.vad_iterator.reset_states() combied_audio = np.concatenate(speech_segments, axis=0).tobytes() if len(speech_segments) else b"" in_data.audio = combied_audio in_data.source_audio = b"" return in_data12344567
from .base import MetaItem, BasePipe, Segmentfrom ..whisper import WhisperCPPfrom ..helpers.whisper import WhisperCPP
class WhisperPipe(BasePipe):112345 unmodified lines101112131314151616171819202122231819202122232425262728293031329 unmodified lines424344454647484950515253545556495758596061from transcribe.pipelines import WhisperPipe, TranslatePipe, MetaItemfrom transcribe.pipelines import WhisperPipe, TranslatePipe, MetaItem, VadPipeimport multiprocessing as mpimport config
5 unmodified lines # self.result_queue = mp.Queue() # whisper 转录 self._whisper_pipe = WhisperPipe() self._whisper_pipe = self._launch_process(WhisperPipe()) # llm 翻译 self._translate_pipe = TranslatePipe() self._translate_pipe = self._launch_process(TranslatePipe())
self._whisper_pipe.daemon = True self._whisper_pipe.start()
self._translate_pipe.daemon = True self._translate_pipe.start() # vad self._vad_pipe = self._launch_process(VadPipe()) def _launch_process(self, process_obj): process_obj.daemon = True process_obj.start() return process_obj
def wait_ready(self): self._whisper_pipe.wait() self._translate_pipe.wait() self._vad_pipe.wait() def translate(self, text, src_lang, dst_lang) -> MetaItem: item = MetaItem(9 unmodified lines self._whisper_pipe.input_queue.put(item) return self._whisper_pipe.output_queue.get() def voice_detect(self, audio_buffer:bytes) -> MetaItem: item = MetaItem(source_audio=audio_buffer) self._vad_pipe.input_queue.put(item) return self._vad_pipe.output_queue.get()
if __name__ == "__main__": import soundfile tp = TranslatePipes() # result = tp.translate("你好,今天天气怎么样?", src_lang="zh", dst_lang="en") mel, _, = soundfile.read("assets/jfk.flac") result = tp.transcrible(mel, 'en') # result = tp.transcrible(mel, 'en') result = tp.voice_detect(mel) print(result)
1 unmodified line2345678978 unmodified lines888990919293941 unmodified lineimport textwrapfrom pathlib import Pathimport loggingimport numpy as npfrom scipy.io.wavfile import write
import av78 unmodified lines
output_container.close() return resampled_file
def save_to_wave(filename, data:np.ndarray, sample_rate=16000): write(filename, sample_rate, data)4 unmodified lines567889101112131413141516175 unmodified lines23242526272627282930333132335 unmodified lines3940414243444546474950514849505152535455565758545960615 unmodified lines67686970717273747576777879808182838485868788666768697071899091929394959697989910024 unmodified lines1251261271281291031301311321331342 unmodified lines1371381391121131401411421431444 unmodified lines14915015112412515215315415515628 unmodified lines1851861871601881891901914 unmodified linesimport numpy as npfrom logging import getLogger
import configfrom .utils import save_to_waveimport timeimport jsonimport threadingfrom .server import ServeClientBase
from scipy.io.wavfile import writeimport queueimport collectionsfrom api_model import TransResult, Messagefrom .utils import log_blockfrom .translatepipes import TranslatePipes5 unmodified linestranslate_pipes.wait_ready()logger.info("Pipeline is ready.")
def save_to_wave(filename, data:np.ndarray, sample_rate=16000): write(filename, sample_rate, data)
class PyWhiperCppServe(ServeClientBase): def __init__(self, websocket, language=None, dst_lang=None, client_uid=None,): super().__init__(client_uid, websocket) self.language = language5 unmodified lines self.lock = threading.Lock() self.frames_np = None self._frame_queue = queue.Queue() self._previous_frame_queue = collections.deque(maxlen=2) self.sample_rate = 16000 self.send_ready_state() self.trans_thread = threading.Thread(target=self.speech_to_text) self.trans_thread.daemon = True self.trans_thread.start() self.run_in_thread(self.speech_to_text) self.run_in_thread(self.get_frame_from_queue)
self.text_sep = "" if self.language == "zh" else " "
def run_in_thread(self, func): t = threading.Thread(target=func) t.daemon = True t.start()
def send_ready_state(self): self.websocket.send(json.dumps({ "uid": self.client_uid, "message": self.SERVER_READY,5 unmodified lines self.dst_lang = dst_lang
def add_frames(self, frame_np): self._frame_queue.put(frame_np)
def get_prev_frame(self, ): if len(self._previous_frame_queue) == 2: return self._previous_frame_queue[-1]
def get_frame_from_queue(self,): while True: try: frame_np = self._frame_queue.get(timeout=0.1) # frame_np = item.source_audio # self._previous_frame_queue.appendleft(frame_np.copy()) # prev_frame_np = self.get_prev_frame() # if prev_frame_np is not None: # frame_np = np.concatenate([prev_frame_np[int(-0.05 * self.sample_rate):],frame_np], axis=0) # item = translate_pipes.voice_detect(frame_np.tobytes()) # if item.audio == b"": # continue # self._audio_queue.put(frame_np) with self.lock: if self.frames_np is None: self.frames_np = frame_np.copy() else: self.frames_np = np.append(self.frames_np,frame_np) # frame_np = np.frombuffer(item.audio, dtype=np.float32) with self.lock: if self.frames_np is None: self.frames_np = frame_np.copy() else: self.frames_np = np.append(self.frames_np,frame_np) except queue.Empty: pass
def update_audio_buffer(self, last_offset):24 unmodified lines log_block("LLM translate input", f"{text}") start_time = time.perf_counter() ret = translate_pipes.translate(text, self.language, self.dst_lang) translated_text = ret.translate_content log_block("LLM translate time", f"{(time.perf_counter() - start_time):.3f}", "s") return ret.translate_content log_block("LLM translate out", f"{translated_text}") return translated_text
2 unmodified lines # 当左边确认后,右边段才会进入观察 # 当左边确认后,会从缓冲区中删除对应的buffer,减少下次输入的数据量 left_watch_idx, left_watch_sequences, right_watch_sequences, is_end_sentence = segments_split(segments, audio_buffer) left_watch_string = "".join(i.text for i in left_watch_sequences) right_watch_string = "".join(i.text for i in right_watch_sequences) left_watch_string = self.text_sep.join(i.text for i in left_watch_sequences) right_watch_string = self.text_sep.join(i.text for i in right_watch_sequences) if left_watch_idx != 0: # 将观察字符串临时存储4 unmodified lines # 整句消除 后两句之前的内容 left_watch_idx, left_watch_sequences, right_watch_sequences, is_end_sentence = sequences_split(segments, audio_buffer) left_watch_string = "".join(i.text for i in left_watch_sequences) right_watch_string = "".join(i.text for i in right_watch_sequences) left_watch_string = self.text_sep.join(i.text for i in left_watch_sequences) right_watch_string = self.text_sep.join(i.text for i in right_watch_sequences) if left_watch_idx != 0: return left_watch_idx, left_watch_string, right_watch_string, is_end_sentence 28 unmodified lines # logger.error(f"{e}") def handle_transcription_output(self, segments, audio_buffer): texts = "".join(i.text for i in segments) texts = self.text_sep.join(i.text for i in segments) if not len(texts): return self._segment_manager.handle(texts)15 unmodified lines1617181920212223242526272829303132333435201 unmodified lines237238239240241242243244245246247248249250251252253254255256602 unmodified lines859860861862863864865866867868869870871872873107 unmodified lines981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100968 unmodified lines10781079108010811082108310841085108610871088108910901091109210931094109557 unmodified lines115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118012 unmodified lines1193119411951196119711981199120012011202120312041205120612074 unmodified lines12121213121412151216121712181219122012211222122312241225122615 unmodified lines { url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643 },]
[[package]]name = "anyio"version = "4.9.0"source = { registry = "https://pypi.org/simple" }dependencies = [ { name = "idna" }, { name = "sniffio" }, { name = "typing-extensions", marker = "python_full_version < '3.13'" },]sdist = { url = "https://files.pythonhosted.org/packages/95/7d/4c1bd541d4dffa1b52bd83fb8527089e097a106fc90b467a7313b105f840/anyio-4.9.0.tar.gz", hash = "sha256:673c0c244e15788651a4ff38710fea9675823028a6f08a5eda409e0c9840a028", size = 190949 }wheels = [ { url = "https://files.pythonhosted.org/packages/a1/ee/48ca1a7c89ffec8b6a0c5d02b89c305671d5ffd8d3c94acf8b8c408575bb/anyio-4.9.0-py3-none-any.whl", hash = "sha256:9f76d541cad6e36af7beb62e978876f3b41e3e04f2c1fbf0884604c0a9c4d93c", size = 100916 },]
[[package]]name = "audioop-lts"version = "0.2.1"201 unmodified lines { url = "https://files.pythonhosted.org/packages/4e/8c/f3147f5c4b73e7550fe5f9352eaa956ae838d5c51eb58e7a25b9f3e2643b/decorator-5.2.1-py3-none-any.whl", hash = "sha256:d316bb415a2d9e2d2b3abcc4084c6502fc09240e292cd76a76afc106a1c8e04a", size = 9190 },]
[[package]]name = "fastapi"version = "0.115.12"source = { registry = "https://pypi.org/simple" }dependencies = [ { name = "pydantic" }, { name = "starlette" }, { name = "typing-extensions" },]sdist = { url = "https://files.pythonhosted.org/packages/f4/55/ae499352d82338331ca1e28c7f4a63bfd09479b16395dce38cf50a39e2c2/fastapi-0.115.12.tar.gz", hash = "sha256:1e2c2a2646905f9e83d32f04a3f86aff4a286669c6c950ca95b5fd68c2602681", size = 295236 }wheels = [ { url = "https://files.pythonhosted.org/packages/50/b3/b51f09c2ba432a576fe63758bddc81f78f0c6309d9e5c10d194313bf021e/fastapi-0.115.12-py3-none-any.whl", hash = "sha256:e94613d6c05e27be7ffebdd6ea5f388112e5e430c8f7d6494a9d1d88d43e814d", size = 95164 },]
[[package]]name = "filelock"version = "3.18.0"602 unmodified lines { url = "https://files.pythonhosted.org/packages/12/6f/5596dc418f2e292ffc661d21931ab34591952e2843e7168ea5a52591f6ff/pydantic_core-2.33.1-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:f995719707e0e29f0f41a8aa3bcea6e761a36c9136104d3189eafb83f5cec5e5", size = 2080951 },]
[[package]]name = "pydub"version = "0.25.1"source = { registry = "https://pypi.org/simple" }sdist = { url = "https://files.pythonhosted.org/packages/fe/9a/e6bca0eed82db26562c73b5076539a4a08d3cffd19c3cc5913a3e61145fd/pydub-0.25.1.tar.gz", hash = "sha256:980a33ce9949cab2a569606b65674d748ecbca4f0796887fd6f46173a7b0d30f", size = 38326 }wheels = [ { url = "https://files.pythonhosted.org/packages/a6/53/d78dc063216e62fc55f6b2eebb447f6a4b0a59f55c8406376f76bf959b08/pydub-0.25.1-py2.py3-none-any.whl", hash = "sha256:65617e33033874b59d87db603aa1ed450633288aefead953b30bded59cb599a6", size = 32327 },]
[[package]]name = "pyreadline3"version = "3.5.4"107 unmodified lines { url = "https://files.pythonhosted.org/packages/54/21/f43f0a1fa8b06b32812e0975981f4677d28e0f3271601dc88ac5a5b83220/setuptools-78.1.0-py3-none-any.whl", hash = "sha256:3e386e96793c8702ae83d17b853fb93d3e09ef82ec62722e61da5cd22376dcd8", size = 1256108 },]
[[package]]name = "silero-vad"version = "5.1.2"source = { registry = "https://pypi.org/simple" }dependencies = [ { name = "onnxruntime" }, { name = "torch" }, { name = "torchaudio" },]sdist = { url = "https://files.pythonhosted.org/packages/b1/b4/d0311b2e6220a11f8f4699f4a278cb088131573286cdfe804c87c7eb5123/silero_vad-5.1.2.tar.gz", hash = "sha256:c442971160026d2d7aa0ad83f0c7ee86c89797a65289fe625c8ea59fc6fb828d", size = 5098526 }wheels = [ { url = "https://files.pythonhosted.org/packages/98/f7/5ae11d13fbb733cd3bfd7ff1c3a3902e6f55437df4b72307c1f168146268/silero_vad-5.1.2-py3-none-any.whl", hash = "sha256:93b41953d7774b165407fda6b533c119c5803864e367d5034dc626c82cfdf661", size = 5026737 },]
[[package]]name = "sniffio"version = "1.3.1"source = { registry = "https://pypi.org/simple" }sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372 }wheels = [ { url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235 },]
[[package]]name = "soundfile"version = "0.13.1"68 unmodified lines { url = "https://files.pythonhosted.org/packages/34/ae/e3707f6c1bc6f7aa0df600ba8075bfb8a19252140cd595335be60e25f9ee/standard_sunau-3.13.0-py3-none-any.whl", hash = "sha256:53af624a9529c41062f4c2fd33837f297f3baa196b0cfceffea6555654602622", size = 7364 },]
[[package]]name = "starlette"version = "0.46.1"source = { registry = "https://pypi.org/simple" }dependencies = [ { name = "anyio" },]sdist = { url = "https://files.pythonhosted.org/packages/04/1b/52b27f2e13ceedc79a908e29eac426a63465a1a01248e5f24aa36a62aeb3/starlette-0.46.1.tar.gz", hash = "sha256:3c88d58ee4bd1bb807c0d1acb381838afc7752f9ddaec81bbe4383611d833230", size = 2580102 }wheels = [ { url = "https://files.pythonhosted.org/packages/a0/4b/528ccf7a982216885a1ff4908e886b8fb5f19862d1962f56a3fce2435a70/starlette-0.46.1-py3-none-any.whl", hash = "sha256:77c74ed9d2720138b25875133f3a2dae6d854af2ec37dceb56aef370c1d8a227", size = 71995 },]
[[package]]name = "sympy"version = "1.13.1"57 unmodified lines { url = "https://files.pythonhosted.org/packages/88/8b/d60c0491ab63634763be1537ad488694d316ddc4a20eaadd639cedc53971/torch-2.6.0-cp313-none-macosx_11_0_arm64.whl", hash = "sha256:ff96f4038f8af9f7ec4231710ed4549da1bdebad95923953a25045dcf6fd87e2", size = 66536783 },]
[[package]]name = "torchaudio"version = "2.6.0"source = { registry = "https://pypi.org/simple" }dependencies = [ { name = "torch" },]wheels = [ { url = "https://files.pythonhosted.org/packages/a9/30/bba293c8300245a09b7f82d3cfc04aee1950228da49c6cdd637d1145b6f5/torchaudio-2.6.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c12fc41241b8dfce3ccc1917f1c81a0f92f532d9917706600046f1eb21d2d765", size = 1815253 }, { url = "https://files.pythonhosted.org/packages/3e/00/2c69d436c613043f3051210d2f84a4c9062a815fa609c5f54d25ea8bfd07/torchaudio-2.6.0-cp311-cp311-manylinux1_x86_64.whl", hash = "sha256:377b177a3d683a9163e4cab5a06f0346dac9ff96fa527477338fd90fc6a2a4b6", size = 3382518 }, { url = "https://files.pythonhosted.org/packages/f5/b8/7d4dbbf6b505caddbfccd38e2882e47a791310b32b347f977a0a66efbf80/torchaudio-2.6.0-cp311-cp311-manylinux_2_28_aarch64.whl", hash = "sha256:0f0db5c997d031c34066d8be1c0ce7d2a1f2b6c016a92885b20b00bfeb17b753", size = 1652980 }, { url = "https://files.pythonhosted.org/packages/1f/31/417d6955585be76842e9b0159d3801c0b5f9a4ea0db39db1a72bc262c861/torchaudio-2.6.0-cp311-cp311-win_amd64.whl", hash = "sha256:52182f6de4e7b342d139e54b703185d428de9cce3c4cf914a9b2ab2359d192a3", size = 2454430 }, { url = "https://files.pythonhosted.org/packages/ac/4a/d71b932bda4171970bdf4997541b5c778daa0e2967ed5009d207fca86ded/torchaudio-2.6.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7d0e4b08c42325bf4b887de9a25c44ed882997001740e1bd7d901f65581cf1ab", size = 1812899 }, { url = "https://files.pythonhosted.org/packages/ed/aa/9082e715a673dd8e22b6a60cec7f301e897406023672b2090f8bcd8a5959/torchaudio-2.6.0-cp312-cp312-manylinux1_x86_64.whl", hash = "sha256:715aa21f6bdbd085454c313ae3a2c7cc07bf2e8cf05752f819afb5b4c57f4e6f", size = 3379510 }, { url = "https://files.pythonhosted.org/packages/f2/e7/0bcb2e33f4bdec69477344eccfe25c515b90496888095e99f837ea422089/torchaudio-2.6.0-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:6291d9507dc1d6b4ffe8843fbfb201e6c8270dd8c42ad70bb76226c0ebdcad56", size = 1653523 }, { url = "https://files.pythonhosted.org/packages/80/95/29e917905328337c7b104ce81f3bb5e2ad8dc70af2edf1d43f67eb621513/torchaudio-2.6.0-cp312-cp312-win_amd64.whl", hash = "sha256:86d6239792bf94741a41acd6fe3d549faaf0d50e7275d17d076a190bd007e2f9", size = 2449191 }, { url = "https://files.pythonhosted.org/packages/fb/73/861afa5864e95fbf42b693e0359b2bf0177b6b5f4274fa4472fd51e5298e/torchaudio-2.6.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:66f2e0bd5ab56fd81419d2f5afb74a9a70141688594646441756c8c24f424a73", size = 1813188 }, { url = "https://files.pythonhosted.org/packages/d2/f0/daffd9afa60bd835a2d7980eddfe44524adcb3ee0837486ceae4cd1f68e2/torchaudio-2.6.0-cp313-cp313-manylinux1_x86_64.whl", hash = "sha256:52f15185349c370fc1faa84e8b8b2782c007472db9d586a16bba314130b322f2", size = 3380706 }, { url = "https://files.pythonhosted.org/packages/94/7b/887b91372e34119aa140cf67614e5ba901bf6a0db86f2c39e30ff71eec54/torchaudio-2.6.0-cp313-cp313-manylinux_2_28_aarch64.whl", hash = "sha256:b521ea9618fb4c29a6f8071628170c222291f46a48a3bf424cfeb488f54af714", size = 1653553 }, { url = "https://files.pythonhosted.org/packages/55/c8/3010878a5e7f15d89450e22769697173c6dc244a0647ddc5386c28b6dacc/torchaudio-2.6.0-cp313-cp313-win_amd64.whl", hash = "sha256:393fa74ec40d167f0170728ea21c9b5e0f830648fd02df7db2bf7e62f64245ec", size = 2449350 },]
[[package]]name = "tqdm"version = "4.67.1"12 unmodified linessource = { virtual = "." }dependencies = [ { name = "av" }, { name = "fastapi" }, { name = "librosa" }, { name = "numpy" }, { name = "onnxruntime" }, { name = "pyaudio" }, { name = "pydantic" }, { name = "pydub" }, { name = "setuptools" }, { name = "silero-vad" }, { name = "soundfile" }, { name = "torch" }, { name = "tqdm" },4 unmodified lines[package.metadata]requires-dist = [ { name = "av", specifier = ">=14.2.0" }, { name = "fastapi", specifier = ">=0.115.12" }, { name = "librosa", specifier = ">=0.11.0" }, { name = "numpy", specifier = ">=2.1.3" }, { name = "onnxruntime", specifier = ">=1.21.0" }, { name = "pyaudio", specifier = ">=0.2.14" }, { name = "pydantic", specifier = ">=2.11.2" }, { name = "pydub", specifier = ">=0.25.1" }, { name = "setuptools", specifier = ">=78.1.0" }, { name = "silero-vad", specifier = ">=5.1.2" }, { name = "soundfile", specifier = ">=0.13.1" }, { name = "torch", specifier = ">=2.6.0" }, { name = "tqdm", specifier = ">=4.67.1" },.gitignore+1-1
main.pyAdded
moyoyo_asr_models/Qwen2.5-3B.Q5_0.ggufAdded+3
moyoyo_asr_models/qwen2.5-7b-instruct-q5_0-00001-of-00002.ggufAdded+3
moyoyo_asr_models/qwen2.5-7b-instruct-q5_0-00002-of-00002.ggufAdded+3
pyproject.toml+3
requirements.txt+31-23
transcribe/helpers/__init__.pyAdded
transcribe/translator.py → transcribe/helpers/translator.pyRenamed
transcribe/helpers/vadprocessor.pyAdded+251
transcribe/whisper.py → transcribe/helpers/whisper.pyRenamed
transcribe/pipelines/__init__.py+1
transcribe/pipelines/base.py+1
transcribe/pipelines/pipe_translate.py+1-1
transcribe/pipelines/pipe_vad.py+68-1
transcribe/pipelines/pipe_whisper.py+1-1
transcribe/translatepipes.py+19-10
transcribe/utils.py+6
transcribe/whisper_llm_serve.py+50-22
uv.lock+100