小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

獲取百度翻譯的英文句子的讀音

 行者花雕 2022-12-25 發(fā)布于北京
import requests
from io import BytesIO
from urllib.parse import quote
from docx import Document
import time

# 修改cookie
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
    'Accept-Encoding': 'gzip, deflate, br',
    'cookie': '...',
    'Upgrade-Insecure-Requests': '1',
    'TE': 'Trailers',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    'connection': 'keep-alive',
}
URL = "https://fanyi.baidu.com/gettts?lan=en&text=%s&spd=3&source=web"

session = requests.session()
maxlen = 2


def fanyi(no, sentence):
    """
    :param no: 序號(hào)
    :param sentence: 一段英文
    :return: 
    """
    print(sentence, end=" ")
    response = session.get(URL % quote(sentence), headers=headers)
    print("code: ", response.status_code)
    if response.status_code != 200:
        return False

    with open('./2021-03-08/' + str(no) + ".mp3", "wb") as f:
        soud = BytesIO(response.content)
        z = soud.getbuffer()
        f.write(z)
        f.flush()

    return True


def main():
    # 這個(gè)函數(shù)主要是為了獲取文件中的英文,自行修改
    document = Document('./2021-03-08.docx')
    cnt = 0
    for para in document.paragraphs:
        text = para.text
        start, end = text.find('】'), text.find('^')
        if start == -1 or end == -1:
            continue
        cnt += 1

        no = str(cnt)
        if len(no) < maxlen:
            no = '0' * (maxlen - len(no)) + no

        fanyi(no, text[start + 1:end].strip())
        time.sleep(3)

    print(cnt)


if __name__ == '__main__':
    main()

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多