Comments (5)
这是我的代码希望对你有所帮助
import json
import requests
from moviepy.video.io.VideoFileClip import VideoFileClip
from tool.file.fileBasic import listFileSort
import os
import shutil
from tool.file.txt.TxtWriter import BasicWriter
def videoToAudio(file):
# 请求地址
url = "http://127.0.0.1:9977/api"
# 请求参数 file:音视频文件,language:语言代码,model:模型,response_format:text|json|srt
# 返回 code==0 成功,其他失败,msg==成功为ok,其他失败原因,data=识别后返回文字
files = {"file": open(file, "rb")}
data = {"language": "zh", "model": "medium", "response_format": "text"}
response = requests.request("POST", url, timeout=600, data=data, files=files)
text = json.loads(response.text)["data"]
return bytes(text, 'unicode_escape').decode('unicode_escape')
def split_video(input_path, output_prefix, segment_duration):
# 打开视频文件
video_clip = VideoFileClip(input_path)
# 获取视频总时长
total_duration = video_clip.duration
# 计算分割点
split_points = [t for t in range(0, int(total_duration), segment_duration)]
# 分割视频
for i, start_time in enumerate(split_points):
end_time = min(start_time + segment_duration, total_duration)
subclip = video_clip.subclip(start_time, end_time)
subclip.write_videofile(f"{output_prefix}_part_{i + 1}.mp4")
# 关闭视频文件
video_clip.close()
def delete_all_files_in_folder(folder_path):
# 遍历文件夹下的所有文件和子文件夹
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
# 如果是文件,则删除
if os.path.isfile(file_path):
os.remove(file_path)
print(f"Deleted file: {file_path}")
# 如果是子文件夹,则递归调用删除
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
print(f"Deleted folder: {file_path}")
if __name__ == '__main__':
path = r"G:\temp"
files = listFileSort(path)
for file in files:
if os.path.isfile(file):
temp = file.replace("\\", "/")
split_video(file, path + r"\temp\temp", 300)
text = ''
for video in os.listdir(path + r"\temp"):
temp = videoToAudio(path + r"\temp\\" + video)
text = text + temp
print(temp)
BasicWriter(file.replace("mp4", "txt"), text, "w")
delete_all_files_in_folder(path + r"\temp")
delete_all_files_in_folder(r"F:\software\videoToText\sttv-0.91\static\tmp")
from stt.
内部已使用VAD自动按静音分割,应不会存在这个问题
只是vad消耗资源较多,如果视频很大而资源不足,可能出问题
from stt.
10分钟的效果会比5分钟,或者30分钟要好吗,还是其他的说法?
from stt.
还想说将英文电影识别翻译字幕来着,能支持到多大时长的?
from stt.
只要内存足够、显存足够,多大都可以。
无法读取是资源不足。尤其是使用 large大模型时,显示至少要8G以上
from stt.
Related Issues (20)
- 能否提供docker镜像版本
- locale.getdefaultlocale Error in cfg.py HOT 1
- Create voice from SRT file HOT 1
- stt运行时出现的问题
- 处理结果为null
- Error opening output file HOT 1
- 不支持m4a音频文件
- 文件不完整 HOT 1
- model HOT 1
- 数字识别不太好,有什么解决办法吗?
- API报错None Model file does not exist HOT 1
- 请问是否有ROCm(类似CUDA的AMD GPU深度学习框架)支持 HOT 1
- 无法通过内网访问页面和接口
- 配置怎么算的,比如长视频用large的模型,多长时间的视频要用的大概什么样的配置【内存、GPU】 HOT 1
- 进度条卡着0%不动 HOT 1
- Language
- What is the reason for the following error message when the project is identified?
- large-v3
- RuntimeError: parallel_for failed: cudaErrorNoKernelImageForDevice: no kernel image is available for execution on the device
- large-v3是不是只支持英文转换
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stt.