python-3.x - 使用python在Google文本中暂停第二个到语音
问题描述
from gtts import gTTS
import os
import random
with open('symbols.txt', 'r') as file:
symbols = file.read().replace('\n', '')
def getunique():
for r, d, f in os.walk(path):
for file in f:
if file.endswith('.mp3'):
unique.add(file.split('.')[0])
def generate(unique):
chars = symbols
while True:
value = "".join(random.choice(chars) for _ in range(8))
if value not in unique:
language = 'en'
myobj = gTTS(text=value, lang=language, slow=True)
myobj.save("audio_captcha_training_set2/"+value+".mp3")
unique.add(value)
break
path = "C:\\Users\\DNS\\Desktop\\Audio Captcha\\Test Python code\\audio_captcha_training_set\\"
unique = set()
getunique()
for _ in range(20):
generate(unique)
这是一个读取包含 0-9 和 AZ 字符的文件的代码。这是为从文件中读取的随机 8 个字符生成音频,但在生成字符音频时不会出现任何暂停或延迟。我想在每个字符之间添加一秒钟的停顿。有什么帮助吗?
解决方案
推荐阅读
- r - 数据清洗功能:用中位幂代替十的幂
- arrays - 使用访问远程服务器的 bash 脚本打印数组元素的问题
- string - 后缀自动化和 Ukkonen 后缀树的区别
- angular - 在 Angular nx 项目中导入 glsl 文件
- python - 如何在 Python 脚本上动态启用/禁用 Tornado Auth?
- python - python中有没有更简单的编码来使用字典数据结构进行编码和解码
- uncrustify - uncrustify:如何在 else 之后强制尾随 {
- php - 如果引用的表列在 Laravel 6 中使用外键的表之后,则不能在迁移中使用外键
- python - 在熊猫数据框中获取非常复杂条件下的最大值和最小值
- html - 如何将 Angular HTML 文件的默认位置从“从左到右”更改为“从右到左”?