Transcribe and organize voice memos with automatic categorization and information extraction. Use when users have voice notes, audio memos, or spoken notes to convert to structured text.
将语音备忘录转换为组织有序、可搜索的文本,并自动分类和提取关键信息。
安装所需的 Python 包:
bash
pip install requests
python
import requests
def transcribevoicememo(audio_file):
url = https://api.senseaudio.cn/v1/audio/transcriptions
headers = {Authorization: fBearer {API_KEY}}
files = {file: open(audio_file, rb)}
data = {
model: sense-asr, # 标准模型:功能完整,适合语音备忘录
response_format: json
}
response = requests.post(url, headers=headers, files=files, data=data)
return response.json()[text]
将口语化表达转换为可读文本:
python
import re
def clean_transcription(text):
# 移除填充词
fillers = [um, uh, like, you know, basically, actually]
for filler in fillers:
text = re.sub(rf\b{filler}\b, , text, flags=re.IGNORECASE)
# 修正间距
text = re.sub(r\s+, , text).strip()
# 句子首字母大写
sentences = text.split(. )
text = . .join(s.capitalize() for s in sentences)
return text
python
import re
from datetime import datetime
def extract_info(text):
info = {
dates: [],
tasks: [],
contacts: [],
keywords: []
}
# 提取日期
date_patterns = [
r\b(?:tomorrow|today|yesterday)\b,
r\b(?:monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b,
r\b\d{1,2}/\d{1,2}/\d{2,4}\b
]
for pattern in date_patterns:
info[dates].extend(re.findall(pattern, text, re.IGNORECASE))
# 提取任务(动作动词)
task_patterns = [
r(?:need to|have to|must|should)\s+(\w+(?:\s+\w+){0,5}),
r(?:remember to|don\t forget to)\s+(\w+(?:\s+\w+){0,5})
]
for pattern in task_patterns:
info[tasks].extend(re.findall(pattern, text, re.IGNORECASE))
# 提取名称(大写单词)
info[contacts] = re.findall(r\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\b, text)
return info
python
def categorize_memo(text):
categories = {
work: [meeting, project, deadline, client, email],
personal: [family, friend, home, weekend],
shopping: [buy, purchase, store, grocery],
ideas: [idea, think, maybe, could],
tasks: [todo, task, need to, must]
}
text_lower = text.lower()
scores = {}
for category, keywords in categories.items():
score = sum(1 for keyword in keywords if keyword in text_lower)
scores[category] = score
return max(scores, key=scores.get) if max(scores.values()) > 0 else general
python
def processvoicememo(audio_file):
# 转录
rawtext = transcribevoicememo(audiofile)
# 清理
cleantext = cleantranscription(raw_text)
# 提取信息
info = extractinfo(cleantext)
# 分类
category = categorizememo(cleantext)
# 创建结构化备忘录
memo = {
timestamp: datetime.now().isoformat(),
category: category,
text: clean_text,
rawtext: rawtext,
extracted_info: info,
summary: generatesummary(cleantext)
}
return memo
def generate_summary(text):
# 使用第一个句子或前100个字符
sentences = text.split(. )
return sentences[0] if sentences else text[:100]
处理多个备忘录:
python
def processmemobatch(audio_files):
memos = []
for audiofile in audiofiles:
memo = processvoicememo(audio_file)
memos.append(memo)
# 按类别分组
by_category = {}
for memo in memos:
category = memo[category]
if category not in by_category:
by_category[category] = []
by_category[category].append(memo)
return by_category
python
def search_memos(memos, query):
results = []
query_lower = query.lower()
for memo in memos:
if query_lower in memo[text].lower():
results.append(memo)
return results
def filterbydate(memos, date):
return [m for m in memos if date in m[extracted_info][dates]]
python
def exporttomarkdown(memos):
md = # 语音备忘录\n\n
for memo in memos:
md += f## {memo[timestamp]}\n
md += f类别: {memo[category]}\n\n
md += f{memo[text]}\n\n
if memo[extracted_info][tasks]:
md += 任务:\n
for task in memo[extracted_info][tasks]:
md += f- [ ] {task}\n
md += \n
return md
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 memo-1776113473 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 memo-1776113473 技能
skillhub install memo-1776113473
文件大小: 2.93 KB | 发布时间: 2026-4-14 13:13