3 Star 5 Fork 2

新媒体网络营销/针对cosyvoice开发的大文本转语音处理工具_听书狂人处理机

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
title_extractor.py 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
import jieba
import threading
import logging
logger = logging.getLogger(__name__)
def extract_book_title(text):
"""
使用 jieba 提取文本中的可能书名关键词。
"""
try:
words = jieba.lcut(text)
potential_titles = [word for word in words if len(word) > 2]
if potential_titles:
logger.info(f"识别到的可能书名:{potential_titles}")
return potential_titles[0]
else:
logger.warning("未识别到任何可能的书名")
return None
except Exception as e:
logger.error(f"书名提取失败: {e}")
return None
def find_book_title(text, timeout_seconds=6):
"""
尝试提取书名,并在指定的超时时间内返回结果。
如果超时或失败,记录日志并返回 None。
"""
result = [None]
def worker():
try:
result[0] = extract_book_title(text)
except Exception as e:
logger.error(f"Worker 函数中发生错误: {e}", exc_info=True)
timer = threading.Timer(timeout_seconds, lambda: logger.error("书名提取操作超时,进入下一步程序"))
try:
logger.info("启动书名提取的超时计时器")
timer.start()
worker()
except Exception as e:
logger.error(f"find_book_title 函数中发生错误: {e}", exc_info=True)
finally:
timer.cancel()
logger.info("超时计时器已取消")
return result[0]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xinmeitiyingxiao/lingting.git
git@gitee.com:xinmeitiyingxiao/lingting.git
xinmeitiyingxiao
lingting
针对cosyvoice开发的大文本转语音处理工具_听书狂人处理机
master

搜索帮助