調用部分一與二,完成文本至MP3文件的轉化。
interface.py
# 20190526
import sys
import url2txt # 網址提取文本
import TTS_API # 文本信息轉換為語音
# 自動播放模塊未寫
import math
root_path = sys.path[0]
txt_path = root_path+'\\'+'txt_file'
audio_path = root_path+'\\'+'audio_file'
chunk = 500 # 字節
url = 'https://zhuanlan.zhihu.com/p/61617200'
txt_data = url2txt.url2txt(url,txt_path,'content')
len_data = len(txt_data)
num_audio = math.ceil(len_data/chunk)
x = 0
y = chunk
for single in range(0,num_audio):
TTS_API.TTS(txt_data[x:y],audio_path,str(single))
x = y
y = y+chunk