当前位置: 首页 > news >正文

本地进行语音文字互转

文字转语音 ChatTTS

https://github.com/2noise/ChatTTS

  • 用下面的代码即可实现,输出一个wav音频文件,即为转化的结果
from torch import manual_seedimport ChatTTS
import torch
import torchaudiochat = ChatTTS.Chat()
chat.load(compile=True) # Set to True for better performancetexts = ["今年上半年,各地因地制宜,加快建设各具特色的产业集群。"]# 设置种子, 保持音色稳定
torch.manual_seed(120)wavs = chat.infer(texts)for i in range(len(wavs)):"""In some versions of torchaudio, the first line works but in other versions, so does the second line."""try:torchaudio.save(f"basic_output{i}.wav", torch.from_numpy(wavs[i]).unsqueeze(0), 24000, format="wav")except:torchaudio.save(f"basic_output{i}.wav", torch.from_numpy(wavs[i]), 24000, format="wav")
  • 需要安装soundfile来处理音频格式
pip install soundfile

RuntimeError: narrow(): length must be non-negative.

  • transformer版本问题导致的,运行下面命令即可解决
pip install transformers==4.53.2

https://github.com/2noise/ChatTTS/issues/955

语音转文字 whisper

https://github.com/openai/whisper

  • 把上面转出来的wav文件,用whisper再转成文字,按照官方代码实例即可
http://www.xdnf.cn/news/1271089.html

相关文章:

  • P1890 gcd区间
  • C++11中的移动语义
  • 【无标题】AI 赋能日常效率:实用案例与操作心得分享
  • B.10.01.6-DDD领域驱动设计:从理论到落地的完整指南
  • 数据挖掘2.6 Perceptron Modeling 感知器建模
  • Qdrant Filtering:must / should / must_not 全解析(含 Python 实操)
  • 心灵笔记:正念冥想
  • 解决python错误:playwright._impl._errors.TimeoutError: Timeout 30000ms exceeded.
  • 3.5.2_1 随机访问介质访问控制
  • Python中的Lambda函数详解
  • 【排序算法】④堆排序
  • NTP /Chrony 网络时间协议
  • Leetcode-19. 删除链表的倒数第 N 个结点
  • 比较useCallback、useMemo 和 React.memo
  • 机器学习 K-Means聚类 无监督学习
  • 第4章 程序段的反复执行for语句P115练习题(题及答案)
  • 元宇宙技术如何改变社交方式?
  • 哈希与安全
  • pgAdmin 仪表盘的system部分不能显示,报SYSTEM_STATS扩展没有安装
  • C++ 中的智能指针
  • Qt 综述:从基础到一般应用
  • 机器翻译中的语言学基础详解(包括包括语法、句法和语义学等)
  • 记一次奇异的bug
  • n8n 入门指南:更适合跨境出海搞钱的AI智能体
  • 基于 InfluxDB 的服务器性能监控系统实战(一)
  • vue3上传的文件在线查看
  • 【linux基础】Linux命令提示符解析与操作指南
  • 如何在 Ubuntu 24.04 LTS Linux 上安装 Azure Data Studio
  • 编译技术的两条演化支线:从前端 UI 框架到底层编译器的智能测试
  • “自动报社保 + 查询导出 ” 的完整架构图和 Playwright C# 项目初始化模板