当前位置:网站首页>剪映+json解析将视频中的声音转换成文本
剪映+json解析将视频中的声音转换成文本
2022-07-06 14:29:00 【fangye945a】
前言
有时候我们想将一段视频中的音频转换成文本,最简单最笨的方法就是通过人耳去听,然后通过打字打出来。但这种方法无疑是十分费劲的。机智的小伙伴肯定都知道我们可以借助语音识别工具来做这件事,但是比较现实的一点就是,很多识别软件不是要收费,就是识别准确率比较低。那么我们有什么办法可以既不花钱又准确的将视频中的音频转换成文本呢?
解决方法
有剪辑经验的小伙伴一定知道,剪映这款软件的字幕识别功能,其背后有字节跳动的语音识别技术支撑,对普通话的识别准确率是杠杠的。但是有一点是,他识别的字幕是分段的,要将它们一条条复制出来组成完整的文本,其工作量也不少。
那么,下面介绍一个简单的办法:
具体操作步骤
- 1.下载windows版本的剪映
- 2.导入视频
- 3.识别字幕(导入视频后,点击文本->智能字幕->开始识别即可)

- 4.等待一段时间后(时间长短与视频文件大小有关),就会自动生成字幕了。
- 5.生成字幕后,关闭剪映,会自动保存为草稿。此时再打开剪映,右上角会出现草稿参数的方框,在方框中我们可以找到草稿保存的路径。

- 6.在windows资源管理器中打开保存位置,可以看到如下文件。

- 7.根据英文名称不难找出,draft_content.json 中就是我们草稿内容,刚刚生成的字幕文本也保存在这个json文件中。
- 8.既然是json文件,下一步自然就是json解析了,我们将字幕内容从这个文件中提取出来即可。
- 9.分析json文件,找出要解析的字段, 简化后的json结构如下:
{"materials":{"texts":[{"content":"<font id=\"\" path=\"D:/Program Files/JianyingPro/3.0.5.8542/Resources/Font/SystemFont/zh-hans.ttf\"><color=(1.000000, 1.000000, 1.000000, 1.000000)><size=5.000000>同学们好</size></color></font>"}]}}
而我们需要的字幕内容,被三个xml元素标签包裹。
- 10.我们先通过json解析获取到content字段的内容,然后通过字符串处理的方法剔除xml标签,获取最终文本字幕内容。
如下是我写的一个简单的python脚本,可以方便快捷的处理剪映这个包含字幕的json文件:
import json
if __name__ == '__main__':
with open("draft_content.json", "r", encoding='utf-8') as f:
json_str = f.read()
json_content = json.loads(json_str)
texts_data = json_content["materials"]["texts"]
for text_data in texts_data:
content = text_data["content"]
content = content[:-22]
result = content.split("><size=")[1].split(">")[1]
print(result)
- 11.直接将脚本与json文件放置在同一目录下,执行python脚本即可得到需要的字幕内容。

我们还可以通过重定向符号,直接将输出的内容生成文件
python3 parse_jianyin.py >> output.txt

边栏推荐
- Chapter 3: detailed explanation of class loading process (class life cycle)
- Management background --4, delete classification
- Force buckle 575 Divide candy
- Spatial domain and frequency domain image compression of images
- OpenCV VideoCapture. Get() parameter details
- GPS从入门到放弃(十五)、DCB差分码偏差
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
- Management background --2 Classification list
- SQL Server生成自增序号
- GPS从入门到放弃(二十)、天线偏移
猜你喜欢

0 basic learning C language - digital tube

Chapter 3: detailed explanation of class loading process (class life cycle)

GPS from entry to abandonment (XVII), tropospheric delay

About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness

Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution

HDR image reconstruction from a single exposure using deep CNNs阅读札记

Leetcode question brushing (XI) -- sequential questions brushing 51 to 55

Powerful domestic API management tool

HDR image reconstruction from a single exposure using deep CNN reading notes

CCNA Cisco network EIGRP protocol
随机推荐
GNN,请你的网络层数再深一点~
基於 QEMUv8 搭建 OP-TEE 開發環境
Management background --3, modify classification
AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
Oracle性能分析3:TKPROF简介
墨西哥一架飞往美国的客机起飞后遭雷击 随后安全返航
解决项目跨域问题
GPS从入门到放弃(十九)、精密星历(sp3格式)
Chapter 4: talk about class loader again
Problems in the process of opencv300 cmake generating project
HDR image reconstruction from a single exposure using deep CNN reading notes
labelimg的安装与使用
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
12、 Start process
经纪xx系统节点VIP案例介绍和深入分析异常
Inno Setup 打包及签名指南
重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障
MariaDb数据库管理系统的学习(一)安装示意图
NetXpert XG2帮您解决“布线安装与维护”难题
嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利