Skip to content

Instantly share code, notes, and snippets.

@BHznJNs
BHznJNs / sync-private-repo.yaml
Created December 5, 2025 09:32
A GitHub Action script that can sync a private repo of one user to another repo of another user.
name: Sync Private Repository
on:
workflow_dispatch:
jobs:
mirror-sync:
runs-on: ubuntu-latest
permissions:
contents: write
@BHznJNs
BHznJNs / inject_vars.rs
Created October 27, 2025 13:29
Tauri plugin that is used to inject variables into the webview global namespace.
use std::collections::HashMap;
use tauri::{
plugin::{Builder, TauriPlugin},
Runtime,
};
fn create_init_script(vars: HashMap<&str, String>) -> String {
let vars_str = vars
.iter()
import win32clipboard
import win32con
import win32gui
import win32api
import ctypes
import threading
import time
# 手动定义 win32con 中缺失的常量
WM_CLIPBOARDUPDATE = 0x031D
import ctypes
import win32api
import win32con
import win32gui
import pywintypes
from ctypes import wintypes
# 1. 使用 ctypes 定义 pywin32 未封装的 API 和结构体 (已完全修正)
# =================================================================
@BHznJNs
BHznJNs / apply_theme.rs
Created July 28, 2025 07:58
A rust module for tauri applications that provides a trait which can let window background color automatically adapts to the configurated theme.
use dark_light;
use tauri::{
AppHandle,
Manager,
Theme,
WebviewWindowBuilder,
};
use crate::app_state::AppState;
enum ConfigTheme { System, Light, Dark }
@BHznJNs
BHznJNs / BaseRecorder.py
Last active July 27, 2025 10:29
A model that can captures the environment noise sample audio, and use it to reduce the noise for frames, then do VAD on frames, finally writes the audio data that contains a sentence into a .wav file.
import threading
import pyaudio
from abc import ABC, abstractmethod
from contextlib import contextmanager
from loguru import logger
class BaseRecorder(ABC):
def __init__(self, frame_size: int, channels: int):
self.frame_size = frame_size
self.format = pyaudio.paInt16
@BHznJNs
BHznJNs / SenseVoiceModel
Last active July 24, 2025 13:20
Runs SenseVoice.cpp in Python
from typing import Literal
class SenseVoiceModel:
def __init__(self, executable_path: str, model_path: str):
self._executable_path = executable_path
self._model_path = model_path
@staticmethod
def remove_timedata(transcript_text: str) -> str:
import re
@BHznJNs
BHznJNs / sensevoice_sherpa_onnx.py
Created July 24, 2025 09:55
Run SenseVoice model locally with sherpa-onnx
import sherpa_onnx
import soundfile as sf
import numpy as np
from modelscope import snapshot_download
sensevoice_model_id = "WEAAEW/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17"
model_dir = snapshot_download(sensevoice_model_id, local_dir="./sensevoice")
recognizer = sherpa_onnx.OfflineRecognizer.from_sense_voice(
model=f"{model_dir}/model.onnx",
@BHznJNs
BHznJNs / audio_preprocessor.py
Created July 22, 2025 15:57
An audio preprocessor module for applications that uses Whisper or Faster-Whisper to STT.
import numpy as np
import noisereduce as nr
from loguru import logger
from pydub import AudioSegment
from pydub.silence import split_on_silence
def load_audio_file(audio_path: str) -> AudioSegment | None:
try:
audio = AudioSegment\
.from_file(audio_path)\
@BHznJNs
BHznJNs / generate-uwp-icon.sh
Created July 21, 2025 09:22
A bash script to generate the icon assets that is needed for MSIX generating and powered by ImageMagick
#!/bin/bash
# -----------------------------------------------------------------------------
# MSIX 图标资产生成脚本 (使用 ImageMagick) - v3 (最新语法)
#
# 用法:
# bash generate-uwp-icon.sh <path_to_master_image.png>
#
# 描述:
# 此脚本使用 ImageMagick 7+ 的最新、最简洁的语法,不会产生弃用警告。
# -----------------------------------------------------------------------------