{"id":1144118,"date":"2025-01-08T22:56:55","date_gmt":"2025-01-08T14:56:55","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1144118.html"},"modified":"2025-01-08T22:56:57","modified_gmt":"2025-01-08T14:56:57","slug":"%e5%a6%82%e4%bd%95python%e4%b8%80%e4%b8%aa%e5%8d%95%e8%af%8d%e4%b8%80%e4%b8%aa%e5%8d%95%e8%af%8d%e7%9a%84%e8%af%bb%e5%87%ba","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1144118.html","title":{"rendered":"\u5982\u4f55python\u4e00\u4e2a\u5355\u8bcd\u4e00\u4e2a\u5355\u8bcd\u7684\u8bfb\u51fa"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24181401\/b958b98b-4b07-43a0-b903-122c4c04ffcf.webp\" alt=\"\u5982\u4f55python\u4e00\u4e2a\u5355\u8bcd\u4e00\u4e2a\u5355\u8bcd\u7684\u8bfb\u51fa\" \/><\/p>\n<p><p> <strong>\u5982\u4f55python\u4e00\u4e2a\u5355\u8bcd\u4e00\u4e2a\u5355\u8bcd\u7684\u8bfb\u51fa<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5c06\u6587\u672c\u6587\u4ef6\u6216\u5b57\u7b26\u4e32\u5185\u5bb9\u4e00\u4e2a\u5355\u8bcd\u4e00\u4e2a\u5355\u8bcd\u5730\u8bfb\u51fa\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002<strong>\u4f7f\u7528\u5b57\u7b26\u4e32\u5206\u5272\u3001\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u3001\u904d\u5386\u5355\u8bcd<\/strong>\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u5173\u952e\u6b65\u9aa4\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u8fd9\u51e0\u4e2a\u6b65\u9aa4\u6765\u5b9e\u73b0\u4e00\u4e2a\u5355\u8bcd\u4e00\u4e2a\u5355\u8bcd\u7684\u8bfb\u51fa\uff0c\u5e76\u63a2\u8ba8\u5982\u4f55\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6587\u672c\u8f93\u5165\u3001\u4f18\u5316\u4ee3\u7801\u6027\u80fd\u53ca\u9519\u8bef\u5904\u7406\u7b49\u65b9\u9762\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5b57\u7b26\u4e32\u5206\u5272<\/h3>\n<\/p>\n<p><p>\u5b57\u7b26\u4e32\u5206\u5272\u662f\u5b9e\u73b0\u5355\u8bcd\u8bfb\u51fa\u7684\u57fa\u7840\u65b9\u6cd5\u4e4b\u4e00\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5b57\u7b26\u4e32\u64cd\u4f5c\u65b9\u6cd5\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>split()<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>1.1\u3001\u57fa\u7840\u7528\u6cd5<\/h4>\n<\/p>\n<p><p><code>split()<\/code>\u51fd\u6570\u6839\u636e\u7a7a\u683c\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u6210\u5355\u8bcd\u5217\u8868\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">text = &quot;Hello world! This is a test.&quot;<\/p>\n<p>words = text.split()<\/p>\n<p>for word in words:<\/p>\n<p>    print(word)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<strong>\u5b57\u7b26\u4e32\u4e2d\u7684\u6bcf\u4e2a\u5355\u8bcd<\/strong>\u90fd\u88ab\u5355\u72ec\u6253\u5370\u51fa\u6765\u3002<code>split()<\/code>\u51fd\u6570\u9ed8\u8ba4\u4f7f\u7528\u7a7a\u683c\u4f5c\u4e3a\u5206\u9694\u7b26\uff0c\u4f46\u4e5f\u53ef\u4ee5\u6307\u5b9a\u5176\u4ed6\u5206\u9694\u7b26\u3002<\/p>\n<\/p>\n<p><h4>1.2\u3001\u5904\u7406\u590d\u6742\u6587\u672c<\/h4>\n<\/p>\n<p><p>\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6587\u672c\u53ef\u80fd\u5305\u542b\u5404\u79cd\u6807\u70b9\u7b26\u53f7\u548c\u7279\u6b8a\u5b57\u7b26\u3002\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u66f4\u7cbe\u786e\u5730\u62c6\u5206\u5355\u8bcd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>text = &quot;Hello, world! This is a test.&quot;<\/p>\n<p>words = re.findall(r&#39;\\b\\w+\\b&#39;, text)<\/p>\n<p>for word in words:<\/p>\n<p>    print(word)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<strong>\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\u5339\u914d\u6240\u6709\u5355\u8bcd\u5b57\u7b26\uff0c\u5ffd\u7565\u6807\u70b9\u7b26\u53f7\uff0c\u4ece\u800c\u66f4\u52a0\u51c6\u786e\u5730\u62c6\u5206\u6587\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u6587\u672c\u6587\u4ef6\u65f6\uff0c\u5c06\u6574\u4e2a\u6587\u4ef6\u5185\u5bb9\u8bfb\u5165\u5185\u5b58\u5e76\u4e00\u6b21\u6027\u62c6\u5206\u53ef\u80fd\u5bfc\u81f4\u5185\u5b58\u6ea2\u51fa\u3002\u56e0\u6b64\uff0c\u9010\u884c\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u5e76\u9010\u884c\u5904\u7406\u662f\u4e00\u4e2a\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h4>2.1\u3001\u9010\u884c\u8bfb\u53d6\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u9010\u884c\u8bfb\u53d6\u6587\u4ef6\u5e76\u62c6\u5206\u5355\u8bcd\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&#39;example.txt&#39;, &#39;r&#39;) as file:<\/p>\n<p>    for line in file:<\/p>\n<p>        words = line.split()<\/p>\n<p>        for word in words:<\/p>\n<p>            print(word)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>with<\/code>\u8bed\u53e5\u786e\u4fdd\u6587\u4ef6\u5728\u8bfb\u53d6\u5b8c\u6bd5\u540e\u81ea\u52a8\u5173\u95ed\uff0c<strong>\u9010\u884c\u5904\u7406<\/strong>\u80fd\u6709\u6548\u51cf\u5c11\u5185\u5b58\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h4>2.2\u3001\u5904\u7406\u5927\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u975e\u5e38\u5927\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u751f\u6210\u5668\u6765\u9010\u884c\u5904\u7406\u6587\u672c\uff0c\u4ee5\u8fdb\u4e00\u6b65\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def read_words(file_path):<\/p>\n<p>    with open(file_path, &#39;r&#39;) as file:<\/p>\n<p>        for line in file:<\/p>\n<p>            for word in line.split():<\/p>\n<p>                yield word<\/p>\n<p>for word in read_words(&#39;example.txt&#39;):<\/p>\n<p>    print(word)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528\u751f\u6210\u5668\u51fd\u6570<code>read_words()<\/code>\uff0c\u6bcf\u6b21\u53ea\u52a0\u8f7d\u5f53\u524d\u884c\u7684\u5355\u8bcd\uff0c\u51cf\u5c11\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u904d\u5386\u5355\u8bcd<\/h3>\n<\/p>\n<p><p>\u5728\u83b7\u53d6\u5355\u8bcd\u5217\u8868\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5404\u79cd\u904d\u5386\u65b9\u6cd5\u6765\u5904\u7406\u5355\u8bcd\uff0c\u5982\u7edf\u8ba1\u8bcd\u9891\u3001\u8fc7\u6ee4\u7279\u5b9a\u8bcd\u7b49\u3002<\/p>\n<\/p>\n<p><h4>3.1\u3001\u7edf\u8ba1\u8bcd\u9891<\/h4>\n<\/p>\n<p><p>\u7edf\u8ba1\u8bcd\u9891\u662f\u6587\u672c\u5206\u6790\u4e2d\u7684\u5e38\u89c1\u4efb\u52a1\u3002\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>collections.Counter<\/code>\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import Counter<\/p>\n<p>text = &quot;Hello world! This is a test. Hello ag<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.&quot;<\/p>\n<p>words = re.findall(r&#39;\\b\\w+\\b&#39;, text)<\/p>\n<p>word_count = Counter(words)<\/p>\n<p>print(word_count)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>Counter<\/code>\u5bf9\u8c61\u53ef\u4ee5\u76f4\u63a5\u5bf9\u5355\u8bcd\u5217\u8868\u8fdb\u884c\u8ba1\u6570\uff0c\u8f93\u51fa\u6bcf\u4e2a\u5355\u8bcd\u7684\u9891\u7387\u3002<\/p>\n<\/p>\n<p><h4>3.2\u3001\u8fc7\u6ee4\u7279\u5b9a\u8bcd<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u9700\u8981\u8fc7\u6ee4\u6389\u67d0\u4e9b\u7279\u5b9a\u7684\u8bcd\uff0c\u5982\u505c\u7528\u8bcd\u3002\u53ef\u4ee5\u901a\u8fc7\u5217\u8868\u63a8\u5bfc\u5f0f\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">stop_words = {&#39;is&#39;, &#39;a&#39;, &#39;this&#39;}<\/p>\n<p>filtered_words = [word for word in words if word.lower() not in stop_words]<\/p>\n<p>for word in filtered_words:<\/p>\n<p>    print(word)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u8fc7\u6ee4\u6389\u4e86<code>stop_words<\/code>\u5217\u8868\u4e2d\u7684\u8bcd\uff0c\u4ec5\u6253\u5370\u5176\u4ed6\u5355\u8bcd\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6587\u672c\u8f93\u5165<\/h3>\n<\/p>\n<p><p>\u4e0d\u540c\u7c7b\u578b\u7684\u6587\u672c\u8f93\u5165\uff0c\u5982\u7f51\u9875\u5185\u5bb9\u3001PDF\u6587\u4ef6\u7b49\uff0c\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684\u5e93\u548c\u65b9\u6cd5\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>4.1\u3001\u5904\u7406\u7f51\u9875\u5185\u5bb9<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>requests<\/code>\u548c<code>BeautifulSoup<\/code>\u5e93\u6765\u6293\u53d6\u548c\u89e3\u6790\u7f51\u9875\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>url = &#39;http:\/\/example.com&#39;<\/p>\n<p>response = requests.get(url)<\/p>\n<p>soup = BeautifulSoup(response.text, &#39;html.parser&#39;)<\/p>\n<p>text = soup.get_text()<\/p>\n<p>words = re.findall(r&#39;\\b\\w+\\b&#39;, text)<\/p>\n<p>for word in words:<\/p>\n<p>    print(word)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6293\u53d6\u7f51\u9875\u5185\u5bb9\u5e76\u63d0\u53d6\u6587\u672c\uff0c\u7136\u540e\u6309\u7167\u524d\u8ff0\u65b9\u6cd5\u62c6\u5206\u5355\u8bcd\u3002<\/p>\n<\/p>\n<p><h4>4.2\u3001\u5904\u7406PDF\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5904\u7406PDF\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528<code>PyPDF2<\/code>\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import PyPDF2<\/p>\n<p>with open(&#39;example.pdf&#39;, &#39;rb&#39;) as file:<\/p>\n<p>    reader = PyPDF2.PdfFileReader(file)<\/p>\n<p>    for page_num in range(reader.numPages):<\/p>\n<p>        page = reader.getPage(page_num)<\/p>\n<p>        text = page.extractText()<\/p>\n<p>        words = re.findall(r&#39;\\b\\w+\\b&#39;, text)<\/p>\n<p>        for word in words:<\/p>\n<p>            print(word)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>PyPDF2<\/code>\u5e93\u53ef\u4ee5\u8bfb\u53d6PDF\u6587\u4ef6\u5e76\u63d0\u53d6\u6bcf\u9875\u6587\u672c\uff0c\u968f\u540e\u6309\u5355\u8bcd\u62c6\u5206\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f18\u5316\u4ee3\u7801\u6027\u80fd\u53ca\u9519\u8bef\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u6587\u672c\u6216\u590d\u6742\u6587\u672c\u65f6\uff0c\u4f18\u5316\u4ee3\u7801\u6027\u80fd\u548c\u9519\u8bef\u5904\u7406\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><h4>5.1\u3001\u4f18\u5316\u6027\u80fd<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u751f\u6210\u5668<\/strong>\uff1a\u51cf\u5c11\u5185\u5b58\u4f7f\u7528\u3002<\/li>\n<li><strong>\u591a\u7ebf\u7a0b\u5904\u7406<\/strong>\uff1a\u52a0\u901f\u5904\u7406\u901f\u5ea6\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from concurrent.futures import ThreadPoolExecutor<\/p>\n<p>def process_line(line):<\/p>\n<p>    return re.findall(r&#39;\\b\\w+\\b&#39;, line)<\/p>\n<p>with open(&#39;example.txt&#39;, &#39;r&#39;) as file:<\/p>\n<p>    lines = file.readlines()<\/p>\n<p>with ThreadPoolExecutor(max_workers=4) as executor:<\/p>\n<p>    results = executor.map(process_line, lines)<\/p>\n<p>for words in results:<\/p>\n<p>    for word in words:<\/p>\n<p>        print(word)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>ThreadPoolExecutor<\/code>\u5e76\u884c\u5904\u7406\u6587\u4ef6\u7684\u6bcf\u4e00\u884c\uff0c\u63d0\u9ad8\u5904\u7406\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>5.2\u3001\u9519\u8bef\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6587\u672c\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\uff0c\u5982\u6587\u4ef6\u4e0d\u5b58\u5728\u3001\u7f16\u7801\u9519\u8bef\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528<code>try-except<\/code>\u8bed\u53e5\u8fdb\u884c\u6355\u83b7\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    with open(&#39;example.txt&#39;, &#39;r&#39;) as file:<\/p>\n<p>        for line in file:<\/p>\n<p>            words = line.split()<\/p>\n<p>            for word in words:<\/p>\n<p>                print(word)<\/p>\n<p>except FileNotFoundError:<\/p>\n<p>    print(&quot;File not found.&quot;)<\/p>\n<p>except UnicodeDecodeError:<\/p>\n<p>    print(&quot;Encoding error.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u6355\u83b7\u7279\u5b9a\u5f02\u5e38\uff0c\u786e\u4fdd\u7a0b\u5e8f\u5728\u9047\u5230\u9519\u8bef\u65f6\u4e0d\u4f1a\u5d29\u6e83\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u60a8\u5e94\u8be5\u5df2\u7ecf\u4e86\u89e3\u4e86\u5982\u4f55\u5728Python\u4e2d\u5c06\u6587\u672c\u6587\u4ef6\u6216\u5b57\u7b26\u4e32\u5185\u5bb9\u4e00\u4e2a\u5355\u8bcd\u4e00\u4e2a\u5355\u8bcd\u5730\u8bfb\u51fa\u3002<strong>\u4f7f\u7528\u5b57\u7b26\u4e32\u5206\u5272\u3001\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u3001\u904d\u5386\u5355\u8bcd<\/strong>\u7b49\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u60a8\u9ad8\u6548\u5730\u5904\u7406\u6587\u672c\u3002\u5e0c\u671b\u8fd9\u4e9b\u65b9\u6cd5\u548c\u6280\u5de7\u80fd\u591f\u5bf9\u60a8\u7684\u5b9e\u9645\u9879\u76ee\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u9010\u5b57\u9010\u8bcd\u5730\u6717\u8bfb\u6587\u672c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u5230\u8bed\u97f3\uff08TTS\uff09\u5e93\u6765\u9010\u5b57\u9010\u8bcd\u5730\u6717\u8bfb\u6587\u672c\u3002\u4e00\u4e2a\u5e38\u7528\u7684\u5e93\u662f<code>gTTS<\/code>\uff08Google Text-to-Speech\uff09\uff0c\u5b83\u80fd\u591f\u5c06\u6587\u672c\u8f6c\u6362\u4e3a\u97f3\u9891\u6587\u4ef6\u3002\u60a8\u53ef\u4ee5\u5c06\u6587\u672c\u62c6\u5206\u4e3a\u5355\u8bcd\uff0c\u7136\u540e\u9010\u4e2a\u5355\u8bcd\u8fdb\u884c\u6717\u8bfb\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5e93\u6765\u5b9e\u73b0\u9010\u5b57\u9010\u8bcd\u6717\u8bfb\u529f\u80fd\uff1f<\/strong><br \/>\u9664\u4e86<code>gTTS<\/code>\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5c1d\u8bd5<code>pyttsx3<\/code>\u5e93\uff0c\u5b83\u662f\u4e00\u4e2a\u79bb\u7ebf\u7684\u6587\u672c\u5230\u8bed\u97f3\u8f6c\u6362\u5e93\u3002\u4f7f\u7528<code>pyttsx3<\/code>\uff0c\u60a8\u53ef\u4ee5\u63a7\u5236\u8bed\u97f3\u7684\u901f\u5ea6\u548c\u97f3\u8c03\uff0c\u9010\u4e2a\u5355\u8bcd\u8fdb\u884c\u6717\u8bfb\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u63a7\u5236\u6717\u8bfb\u7684\u901f\u5ea6\u548c\u97f3\u8c03\uff1f<\/strong><br \/>\u5f53\u4f7f\u7528<code>pyttsx3<\/code>\u5e93\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u8bed\u97f3\u5c5e\u6027\u6765\u63a7\u5236\u6717\u8bfb\u7684\u901f\u5ea6\u548c\u97f3\u8c03\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>engine.setProperty(&#39;rate&#39;, speed)<\/code>\u6765\u8bbe\u7f6e\u8bed\u901f\uff0c\u4f7f\u7528<code>engine.setProperty(&#39;volume&#39;, volume)<\/code>\u6765\u8c03\u6574\u97f3\u91cf\u3002\u8fd9\u4e9b\u8bbe\u7f6e\u53ef\u4ee5\u5e2e\u52a9\u60a8\u6839\u636e\u9700\u8981\u8c03\u6574\u6717\u8bfb\u6548\u679c\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5927\u6587\u672c\uff0c\u786e\u4fdd\u9010\u5b57\u9010\u8bcd\u7684\u6717\u8bfb\u6d41\u7545\uff1f<\/strong><br \/>\u5bf9\u4e8e\u8f83\u957f\u7684\u6587\u672c\uff0c\u53ef\u4ee5\u5c06\u6587\u672c\u5206\u6bb5\u5904\u7406\uff0c\u5e76\u5728\u6717\u8bfb\u6bcf\u4e2a\u5355\u8bcd\u4e4b\u95f4\u6dfb\u52a0\u9002\u5f53\u7684\u5ef6\u8fdf\uff0c\u4ee5\u786e\u4fdd\u6717\u8bfb\u6d41\u7545\u3002\u4f7f\u7528<code>time.sleep()<\/code>\u51fd\u6570\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u8fd9\u6837\u53ef\u4ee5\u7ed9\u6bcf\u4e2a\u5355\u8bcd\u4e4b\u95f4\u7559\u51fa\u8db3\u591f\u7684\u65f6\u95f4\uff0c\u907f\u514d\u8bed\u97f3\u91cd\u53e0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55python\u4e00\u4e2a\u5355\u8bcd\u4e00\u4e2a\u5355\u8bcd\u7684\u8bfb\u51fa \u5728Python\u4e2d\uff0c\u5c06\u6587\u672c\u6587\u4ef6\u6216\u5b57\u7b26\u4e32\u5185\u5bb9\u4e00\u4e2a\u5355\u8bcd\u4e00\u4e2a\u5355\u8bcd\u5730\u8bfb\u51fa\u53ef\u4ee5\u901a\u8fc7 [&hellip;]","protected":false},"author":3,"featured_media":1144123,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1144118"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1144118"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1144118\/revisions"}],"predecessor-version":[{"id":1144129,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1144118\/revisions\/1144129"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1144123"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1144118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1144118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1144118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}