{"id":1941,"date":"2021-10-02T06:52:02","date_gmt":"2021-10-01T22:52:02","guid":{"rendered":"http:\/\/cnliutz.uicp.io\/?p=1941"},"modified":"2021-10-02T06:52:02","modified_gmt":"2021-10-01T22:52:02","slug":"text-to-sound-%e6%96%87%e6%9c%ac%e8%bd%ac%e8%af%ad%e9%9f%b3","status":"publish","type":"post","link":"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=1941","title":{"rendered":"text to sound \u6587\u672c\u8f6c\u8bed\u97f3"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import pyttsx3\n# import requests\n# from bs4 import BeautifulSoup\n# #contents = \"null \"\n# def content(url):\n#     res = requests.get(url)\n#     soup = BeautifulSoup(res.text,'html.parser')\n#     #soup = BeautifulSoup(res.text,'lxml')\n#     articles = &#91;]\n#     for i in range(len(soup.select('p'))):\n#         article = soup.select('p')&#91;i].getText().strip()\n#         articles.append(article)\n#         contents = \" \".join(articles)\n#         return contents\nengine = pyttsx3.init('sapi5')\nvoices = engine.getProperty('voices')\nengine.setProperty('voice', voices&#91;0].id)\n\ndef speak(audio):\n    engine.say(audio)\n    engine.runAndWait()\n    \n# url = str(input(\"Paste article url\\n\"))\n# contents=content(url)\ncontents = ''' 11\u70b9\u805a\u4f1a\u5b8c\uff0c\u8d75\u654f\u72c2\u72ac\u75ab\u82d7\u6253\u7b2c\u4e94\u9488\uff0c\u5e26\u4e0a\u7cbd\u5b50\n\u2026\u2026\u4e0a\u9ad8\u901f\uff0c12\uff1a10\u5206\u5230\u5bb6\u4e86\uff0c\u5403\u7684\u635e\u9762\uff0c\uff0c\u7761\u9192\u5403\u4e24\u5757\u897f\u74dc\uff0c\n\u5929\u8981\u4e0b\u96e8\u4e86\uff0c4\uff1a30\u665a\u4f1a\u8d70\uff0c6\u70b9\u5230\u5bb6\u91cc\u4e86\uff0c\u4eca\u5929\u6ca1\u8bfe\uff0c\n\u8425\u9500\u9009\u4fee\u8bfe\u8003\u8bd5\u6210\u7ee9\u9700\u8981\u5904\u7406\u3002  \n'''\nprint(contents)      ## In case you want to see the content\nspeak(contents)\n#engine.save_to_file\n#engine.runAndWait()  ## In case if you want to save the article as a audio file<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-1941","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/1941","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1941"}],"version-history":[{"count":0,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/1941\/revisions"}],"wp:attachment":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1941"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}