Install
openclaw skills install audio-transcriber音频转录技能 — 使用 OpenAI Whisper 将音频转录为文本,支持实时录音转写、情感分析和多语言翻译。 Trigger: 当用户需要录音转写、实时翻译、语音转录、会议记录、或音频分析时。
openclaw skills install audio-transcriber满足以下条件时加载此技能:
cd D:\coze-local\db
python audio.py hear_enhanced [选项]
参数:
| 参数 | 默认值 | 说明 |
|---|---|---|
--duration | 15 | 录音时长 (秒) |
--device | 0 | 音频输入设备ID |
--model | tiny | Whisper 模型大小 |
--target-lang | en | 目标翻译语言 (en/zh/ja/ko/fr/de/es/ru) |
输出示例:
[Enhanced Hear] Transcript: 今天天气真好
[Enhanced Hear] Emotion detected: happy
[Enhanced Hear] Translated: The weather is really nice today
python audio.py transcribe --duration 10 --model base --output result.wav
python audio.py analyze --duration 5
# 输出: 能量(RMS)、过零率、频谱质心、信号时长
python audio.py capture --duration 15
# 输出: 原始WAV + 降噪后WAV (_clean.wav)
import numpy as np
import whisper
def transcribe_from_bytes(audio_bytes: bytes, model_size: str = "tiny") -> str:
"""直接从音频字节转写,无需ffmpeg"""
audio_np = np.frombuffer(audio_bytes, dtype=np.int16).astype(np.float32) / 32768.0
model = whisper.load_model(model_size)
result = model.transcribe(audio_np)
return result["text"].strip()
def transcribe_from_file(audio_path: str, model_size: str = "base") -> str:
"""从文件转写(支持mp3/wav/m4a)"""
model = whisper.load_model(model_size)
result = model.transcribe(audio_path)
return result["text"].strip()
def detect_emotion(text: str) -> str:
"""基于关键词的情绪检测"""
emotion_words = {
'happy': ['高兴','开心','快乐','愉快','喜悦','兴奋','欢喜'],
'sad': ['悲伤','难过','痛苦','忧郁','沮丧','失落','眼泪'],
'angry': ['愤怒','生气','恼火','愤慨'],
'fear': ['恐惧','害怕','担心','焦虑','紧张','惊慌'],
'surprise': ['惊讶','意外','震惊','吃惊','诧异'],
'disgust': ['厌恶','反感','憎恶','恶心','嫌弃']
}
text_lower = text.lower()
for emotion, words in emotion_words.items():
if any(w in text_lower for w in words):
return emotion
return 'neutral'
D:\coze-local\db\audio.py — 核心实现:transcribe_audio(), cmd_hear_enhanced(), cmd_transcribe(), cmd_analyze(), cmd_capture()D:\coze-local\db\AudioProcessor — 守护进程集成(process_continuous(), get_last_command())D:\coze-local\external\clawhub_skills\wake-word-detector\SKILL.md — 唤醒词检测技能D:\coze-local\external\clawhub_skills\audio-device-diagnostic\SKILL.md — 音频设备诊断D:\coze-local\external\clawhub_skills\core-daemon-launcher\SKILL.md — 守护进程启动pip install openai-whisper pyaudio numpy