import os
import cv2,re
import time
import pyttsx3
import ffmpeg
import subprocess
from PIL import Image
import numpy as np
import imageio
imageio.plugins.freeimage.download()
# 语音合成
def audio(content):
engine = pyttsx3.init()
zh_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ZH-CN_HUIHUI_11.0"
engine.setProperty('voice', zh_voice_id) #设置语音
rate = engine.getProperty('rate') #语速 0-200 当为200时一秒五个字
volume = engine.getProperty('volume') #音量 0-1
print(rate,volume)
engine.save_to_file(content,'test.mp3')
engine.runAndWait() #一定要弄否则报错,数据无法输入保存
engine.stop()
print('audio')
# 图片合成视频
def video(path,fps,size):
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
video = cv2.VideoWriter( 'output.mp4', fourcc,fps,size) #fps帧数率: 1.00帧/秒 1张一秒
for file in os.listdir(path):
img = cv2.imread('%s/%s'%(path,file)) #路径不能带中文
if img is None:
continue
img = cv2.resize(img,size)
video.write(img)
video.release()
def gif(path):
import imageio
gifs = []
for file in os.listdir(path):
gifs.append(imageio.imread('%s/%s'%(path,file)))
imageio.mimsave('text.gif',gifs,fps=1)
def unite(audio,video):
file_name = 'img/'
video_file = 'output.mp4'
audio_file = 'test.mp3'
outfile_name = file_name + '-txt.mp4'
subprocess.call('ffmpeg -i ' + video_file
+ ' -i ' + audio_file + ' -strict -2 -f mp4 '
+ outfile_name, shell=True)
# d = '''语语速快慢具有相对性'''
# print(len(re.sub('[,。 ]','',d)))
# audio(d) #
# video(path='img',fps=1,size=(350,250)) #fps帧数率: 1.00帧/秒 1张一秒
gif(path='img')
# os.popen('test.mp3')
# os.popen('output.mp4')
os.popen('text.gif')
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?