-
-
Save 410063005/7f464d8ca3300c7af43bfbb5af301323 to your computer and use it in GitHub Desktop.
文本转音频
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import urllib | |
def download(word, is_en=True): | |
url = 'https://sp0.baidu.com/-rM1hT4a2gU2pMbgoY3K/gettts?lan=en&text=%s&spd=2&source=alading' %urllib.parse.quote(word) | |
r = requests.get(url) | |
filename = word.replace(' ', '_') | |
if r.status_code == 200: | |
print('downloading %s' %word) | |
else: | |
print('failed download %s' %word) | |
with open(filename + '.mp3', 'wb') as fd: | |
for chunk in r.iter_content(1024): | |
fd.write(chunk) | |
if __name__ == '__main__': | |
with open('word.txt', 'r') as fd: | |
for line in fd: | |
if line.strip() == '': | |
continue | |
download(line.strip()) | |
print('finish') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment