from aip import AipSpeech

bd_k_l = ['11059852', '5Kk01GtG2fjCwpzEkwdn0mjw', 'bp6Wyx377Elq7RsCQZzTBgGUFzLm8G2A']
APP_ID, API_KEY, SECRET_KEY = bd_k_l def gen_bd_mp3(uid, str_):
mp3_dir = 'C:\\Users\\sas\\PycharmProjects\\produce_video\\mymp3\\'
mp3_dir = 'D:\\mymp3\\'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis(str_, 'zh', 1, {
'vol': 5,
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
f_w = '{}{}{}{}'.format(mp3_dir, 'semHAND', uid, '.mp3')
# with open('auido.b.mp3', 'wb') as f:
with open(f_w, 'wb') as f:
f.write(result) import os os_sep = os.sep
this_file_abspath = os.path.abspath(__file__)
this_file_dirname, this_file_name = os.path.dirname(this_file_abspath), os.path.abspath(__file__).split(os_sep)[-1] uid_d = []
f, uid_n = 'html.parp.txt', 0
sen_l = ['。', '\n'] whole_s = ''
with open(f, 'r', encoding='utf-8') as fr:
for i in fr:
whole_s = '{}{}'.format(whole_s, i) # 设置分句的标志符号;可以根据实际需要进行修改
# cutlist = "。!?".decode('utf-8') cutlist = ['\n', '\t', '。', ';', '?', '.', ';', '?', '...', '、、、', ':', '!', '!']
cutlist = ['\n', '\t', '。', ';', '?', '.', '?', '...', '、、、', '!', '!'] # cutlist = [ '。', ';', '?', '.', ';', '?', '...', '、、、',':',':',',']
# cutlist = [ '。', ';', '?', '.', ';', '?', '...', '、、、',':',',','、'] # 检查某字符是否分句标志符号的函数;如果是,返回True,否则返回False
def FindToken(cutlist, char):
if char in cutlist:
return True
else:
return False # 进行分句的核心函数
def Cut(cutlist, lines): # 参数1:引用分句标志符;参数2:被分句的文本,为一行中文字符
l = [] # 句子列表,用于存储单个分句成功后的整句内容,为函数的返回值
line = [] # 临时列表,用于存储捕获到分句标志符之前的每个字符,一旦发现分句符号后,就会将其内容全部赋给l,然后就会被清空 for i in lines: # 对函数参数2中的每一字符逐个进行检查 (本函数中,如果将if和else对换一下位置,会更好懂)
if FindToken(cutlist, i): # 如果当前字符是分句符号
line.append(i) # 将此字符放入临时列表中
l.append(''.join(line)) # 并把当前临时列表的内容加入到句子列表中
line = [] # 将符号列表清空,以便下次分句使用
else: # 如果当前字符不是分句符号,则将该字符直接放入临时列表中
line.append(i)
return l sentence_l = Cut(list(cutlist), list(whole_s))
sentence_l_noblank = []
for i in sentence_l:
if i != '\n':
sentence_l_noblank.append(i.replace('\n', '')) '''
在标点符号正确的情况下分割出自然的句子
''' '''
以句子为单位生成声音
''' from aip import AipSpeech bd_k_l = ['11059852', '5Kk01GtG2fjCwpzEkwdn0mjw', 'bp6Wyx377Elq7RsCQZzTBgGUFzLm8G2A']
APP_ID, API_KEY, SECRET_KEY = bd_k_l def gen_bd_mp3(uid, str_):
mp3_dir = 'C:\\Users\\sas\\PycharmProjects\\produce_video\\mymp3\\'
mp3_dir = 'D:\\mymp3\\'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis(str_, 'zh', 1, {
'vol': 5,
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
f_w = '{}{}{}{}'.format(mp3_dir, 'oneSen', uid, '.mp3')
# with open('auido.b.mp3', 'wb') as f:
with open(f_w, 'wb') as f:
f.write(result) uid_d = {}
uid, uid_n = 43020157, 0
uid_d[uid] = {}
uid_d[uid]['sen_d'], uid_d[uid]['img_l'] = {}, []
for i in sentence_l_noblank:
uid_sen = '{}{}{}'.format(uid, '_', uid_n)
# gen_bd_mp3(uid_sen, i)
uid_n += 1
mp3_dir = 'D:\\mymp3\\'
f_w = '{}{}{}{}'.format(mp3_dir, 'oneSen', uid_sen, '.mp3')
uid_d[uid]['sen_d'][f_w] = i import glob f_img_d = '{}{}{}{}{}'.format(this_file_dirname, os_sep, 'mypng', os_sep, '*.jpg')
imgs = glob.glob(f_img_d)
uid_d[uid]['img_l'] = []
for i in imgs:
if 'logo' in i:
if 'uid' in i:
# print(i)
uid_d[uid]['img_logo_uid'] = i
else:
uid_d[uid]['img_logo_our'] = i
else:
uid_d[uid]['img_l'].append(i) for i in uid_d[uid]:
print(i) import os, time, glob
import cv2 os_sep = os.sep
this_file_abspath = os.path.abspath(__file__)
this_file_dirname, this_file_name = os.path.dirname(this_file_abspath), os.path.abspath(__file__).split(os_sep)[-1] logo_f, logo_f_uid, imgs = uid_d[uid]['img_logo_our'], uid_d[uid]['img_logo_uid'], uid_d[uid]['img_l']
img_size_d = {}
for i in imgs:
img = cv2.imread(i)
w_h_s = '{},{}'.format(img.shape[1], img.shape[0])
if w_h_s not in img_size_d:
img_size_d[w_h_s] = 1
else:
img_size_d[w_h_s] += 1 # 取众数
mode_img_size_wh = [int(i) for i in
sorted(img_size_d.items(), key=lambda mytuple: mytuple[1], reverse=True)[0][0].split(',')]
mode_img_size_wh = [1208, 720]
os_sep = os.sep import imageio imageio.plugins.ffmpeg.download()
from moviepy.editor import VideoFileClip
# f_mp3 = 'g3dbG3g3uidnoBRBlankLine.06.mp3'
import mutagen.id3
from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3
# EasyID3.valid_keys["comment"] = "COMM::'XXX'"
# id3info = MP3(f_mp3, ID3=EasyID3)
# t_spend = id3info.info.length
import cv2
import glob def resize_rescale_pilimg(img_f, w_h_tuple=(mode_img_size_wh[0], mode_img_size_wh[1]), mid_factor=1):
img_n, img_type = img_f.split('.')[-2], img_f.split('.')[-1]
img_n_resize_rescale_pilimg_dir = '{}{}{}'.format(os_sep.join(img_n.split(os_sep)[:-1]), 'resize_rescale_pilimg',
os_sep, img_n.split(os_sep)[-1], os_sep)
img_n_resize_rescale_pilimg = '{}{}{}'.format(img_n_resize_rescale_pilimg_dir, img_n.split(os_sep)[-1], '.PNG')
img_type = 'PNG'
img_f_new = img_n_resize_rescale_pilimg
mid_icon = Image.open(img_f)
mid_icon_w, mid_icon_h = w_h_tuple[0] * mid_factor, w_h_tuple[1] * mid_factor
mid_icon = mid_icon.resize((mid_icon_w, mid_icon_h), Image.ANTIALIAS)
mid_icon.save(img_n_resize_rescale_pilimg, img_type)
return img_f_new from PIL import Image, ImageDraw, ImageFont myfont = ImageFont.truetype("simhei.ttf", encoding="utf-8")
import cv2
import numpy as np
import math br_step = math.floor((mode_img_size_wh[0]) * 0.018) f_v = '{}{}{}{}'.format('D:\\myv\\', uid, int(time.time()), '.avi')
fps, fourcc = 15, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
videoWriter = cv2.VideoWriter(f_v, fourcc, fps, (mode_img_size_wh[0], mode_img_size_wh[1]))
img_seq = 0
for f_mp3 in uid_d[uid]['sen_d']:
screen_str = uid_d[uid]['sen_d'][f_mp3]
screen_str_l = []
br_step_times = math.ceil(len(screen_str) / br_step)
for i in range(br_step_times):
myrow = screen_str[i * br_step:(i + 1) * br_step]
screen_str_l.append(myrow)
screen_str = '\n'.join(screen_str_l)
EasyID3.valid_keys["comment"] = "COMM::'XXX'"
id3info = MP3(f_mp3, ID3=EasyID3)
t_spend = id3info.info.length
imgname = uid_d[uid]['img_l'][img_seq % len(uid_d[uid]['img_l'])]
img_seq += 1
frame = cv2.imread(imgname)
if (frame.shape[1], frame.shape[0]) != (mode_img_size_wh[0], mode_img_size_wh[1]):
imgname = resize_rescale_pilimg(imgname)
frame = cv2.imread(imgname)
else:
pass img1 = cv2.imread(imgname) # 加载图像
img2 = cv2.imread(logo_f) # logo
rows, cols, channels = img2.shape
roi = img1[0:rows, 0:cols] # 取img1的这个区域来处理
img2gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) # 建立logo的二值图,也建立相反的二值图
ret, mask = cv2.threshold(img2gray, 175, 255, cv2.THRESH_BINARY) # 二值化
mask_inv = cv2.bitwise_not(mask) # 做非操作,黑的变白,白的变黑,黑色0,白色255
img1_bg = cv2.bitwise_and(roi, roi, mask=mask) # 与操作 ,参数输入,输出,与mask做and操作,黑色的被填充
img2_fg = cv2.bitwise_and(img2, img2, mask=mask_inv) # 与操作
dst = cv2.add(img1_bg, img2_fg) # 相加
img1[0:rows, 0:cols] = dst # 把添加了logo的该区域赋值回原来的地方 img3 = cv2.imread(logo_f_uid) # logo
rows, cols, channels = img3.shape
rows1, cols1, channels1 = img1.shape
roi = img1[0:rows, cols1 - cols:cols1] # 取img1的这个区域来处理
img3gray = cv2.cvtColor(img3, cv2.COLOR_BGR2GRAY) # 建立logo的二值图,也建立相反的二值图
ret, mask = cv2.threshold(img3gray, 175, 255, cv2.THRESH_BINARY) # 二值化
mask_inv = cv2.bitwise_not(mask) # 做非操作,黑的变白,白的变黑,黑色0,白色255
img1_bg = cv2.bitwise_and(roi, roi, mask=mask) # 与操作 ,参数输入,输出,与mask做and操作,黑色的被填充
img3_fg = cv2.bitwise_and(img3, img3, mask=mask_inv) # 与操作
dst = cv2.add(img1_bg, img3_fg) # 相加
img1[0:rows, cols1 - cols:cols1] = dst # 把添加了logo的该区域赋值回原来的地方 frame = img1
frame_cv2 = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame_pil = Image.fromarray(frame_cv2) # 转为PIL的图片格式
# font = ImageFont.truetype("simhei.ttf", 50, encoding="utf-8")
font_size = math.floor((mode_img_size_wh[0]) * 0.040)
font = ImageFont.truetype("simhei.ttf", font_size, encoding="utf-8")
# ImageDraw.Draw(frame_pil).text((100, 20), mystr, (0, 0, 255), font)
f_x, f_y = math.floor((mode_img_size_wh[0]) * 0.06), math.floor(
mode_img_size_wh[1] * 0.85) - br_step_times * font_size
# ImageDraw.Draw(frame_pil).text((30, mode_img_size_wh[1]-30), mystr, (0, 0, 255), font)
# blue 0,0,255
ImageDraw.Draw(frame_pil).text((f_x, f_y), screen_str, (255, 0, 0), font)
frame_cv2 = cv2.cvtColor(np.array(frame_pil), cv2.COLOR_RGB2BGR)
img = frame_cv2 EasyID3.valid_keys["comment"] = "COMM::'XXX'"
id3info = MP3(f_mp3, ID3=EasyID3)
t_spend = id3info.info.length
myinterval = t_spend*0.01
print(myinterval, '---------------', screen_str)
this_time = time.time()
while time.time() - this_time < myinterval:
# if 1:
videoWriter.write(img)
videoWriter.release() ddd = 9

  

双logo的更多相关文章

  1. win7 64 + Ubuntu 14.04.1 64双系统安装,详解UEFI ~ GPT和legacy ~ MBR区别

    win7 64 + Ubuntu 14.04.1 64双系统安装 背景:我的笔记本之前的系统是window 7 64 + Ubuntu 14.04.1,用UEFI引导系统.安装过程是先装的win7,再 ...

  2. linux笔记本上安装了双显卡驱动(intel+nvidia)

    为了提高linux图形性能并降低功耗,独特的文章. 我用的系统Fedora 20 Xfce x64,在安装驱动程序,以确保系统是最新的版本号. 最好安装gcc.kernel-devel和其他包.己主动 ...

  3. Ubuntu出现卡logo、卡住、黑屏无法正常启动、屏幕和键盘背光无法调节等一系列问题?可能是NVIDIA显卡驱动没装好

    也不知道是幸运还是不幸,我从一开始接触ubuntu就遇到这一系列的问题, 而且一直没有一个彻底解决的办法,搞得我无比头疼,也害得我重装了无数遍系统... 国际惯例,只按照个人习惯和喜好来写,对某些人来 ...

  4. win10 + ubuntu 16.04 双系统安装

    第一次写博客,有错的请指教emmmm 这是因为老师的要求在做课程设计,要用到ubuntu环境,对于这个来说,学长说的是14 16 18都很稳定,但是他在用16.04所以我也用的ubuntu16.04方 ...

  5. 安卓开机logo和开机动画的几种实现方法

    安卓4.2可用方法2-4,第一种方法未验证. 从理论上来说,android 有4个开机启动画面. 第一个应该是U-BOOT的启动画面,有些设备为了满足按动电源即有显示,在UBOOT里加了开机画面,实现 ...

  6. 如何实现Linux+Windows双系统启动

    设置你的计算机根据需要启动 Windows 10 或 Ubuntu 18.04. 尽管 Linux 是一个有着广泛的硬件和软件支持的操作系统,但事实上有时你仍需要使用 Windows,也许是因为有些不 ...

  7. 安装win和xp双系统 若干问题

    装了winxp和linux双系统,后先在winxp下手动格式化了linux系统,后启动时提示grub错误,重新分区后系统也 2010-09-17 21:07 [清风剑] | 分类:Linux | 浏览 ...

  8. Win10/Ubuntu双系统安装常见问题

    目录 1.win10重启无法进入BIOS 2.install ubuntu后黑屏 2.1 解决安装黑屏 2.2 安装英伟达显卡驱动 3.ubuntu中文系统注意 4.Windows系统时间异常 4.1 ...

  9. 安装Ubuntu 16.04双系统详解(Nvidia显卡)

    Ubuntu16.04双系统安装 一.准备工作 设备:惠普台式机,i5-7400.8G内存.1T机械硬盘.NVIDIA GTX1050显卡.预装系统:Win10. 1.下载ubuntu镜像文件,本人使 ...

随机推荐

  1. JavaScript 单例,Hash,抛异常

    1. 单例 ECMA 5 版 记得以前写过几种单例实现,找不到了... function Singleton() { if (this.constructor.instance) { return t ...

  2. 最优化方法系列:SGD、Adam

    整理一下资源,不过最好还是根据书上的理论好好推导一下..... 文章链接:Deep Learning 最优化方法之SGD 72615436 本文是Deep Learning 之 最优化方法系列文章 整 ...

  3. golang zip 压缩,解压(含目录文件)

    每天学习一点go src. 今天学习了zip包的简单使用,实现了含目录的压缩与解压. 写了两个方法,实现了压缩.解压. package ziptest import ( "archive/z ...

  4. 【Redis】二、Redis高级特性

    (三) Redis高级特性   前面我们介绍了Redis的五种基本的数据类型,灵活运用这五种数据类型是使用Redis的基础,除此之外,Redis还有一些特性,掌握这些特性能对Redis有进一步的了解, ...

  5. 2019西安多校联训 Day4

    T1 大水题!!难度简单,显然的贪心策略即可,but... 思路:首先我们按与i点作战后活下来的士兵排序,然后 若当前剩余兵力足够直接减掉战斗死亡人数,如果不够就加 够再打它,但是!我们在考完试观察测 ...

  6. CSDN怎么转载别人的博客

    在参考"如何快速转载CSDN中的博客"后,由于自己不懂html以及markdown相关知识,所以花了一些时间来弄明白怎么转载博客,以下为转载CSDN博客步骤和一些知识小笔记. 参考 ...

  7. mysql insert一条记录后 返回创建记录主键id的方法

    mysql插入数据后返回自增ID的方法 mysql和oracle插入的时候有一个很大的区别是,oracle支持序列做id,mysql本身有一个列可以做自增长字段,mysql在插入一条数据后,如何能获得 ...

  8. TestNG套件测试(一)

    测试套件是用于测试软件程序的行为或一组行为的测试用例集合. 在TestNG中,我们无法在测试源代码中定义一个套件,但它可以由一个XML文件表示,可以灵活配置要运行的测试. 套件用<suite&g ...

  9. PHP上传文件到七牛(Qiniu)

    上传文件到七牛最简单的方式就是使用七牛官方最新的SDK 安装PHP SDK composer require qiniu/php-sdk 上传文件到七牛 use Qiniu\Auth; use Qin ...

  10. Python - 对多继承以及super的一些了解

    Python支持多继承,与C++一样都会出现一种问题:子类继承的多个父类又继承了同一个父类,这时就有可能会出现父类构造方法被调用多次的情况.关于这个问题,我找了一些资料,虽然没有亲自全部验证,这里我总 ...