1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      如何利用Python將.pdf電子書籍轉(zhuǎn)換成音頻有聲讀物

      本篇文章給大家分享的是有關(guān)如何利用Python將. pdf電子書籍轉(zhuǎn)換成音頻有聲讀物,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

      創(chuàng)新互聯(lián)服務(wù)項目包括湟中網(wǎng)站建設(shè)、湟中網(wǎng)站制作、湟中網(wǎng)頁制作以及湟中網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,湟中網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到湟中省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

      有沒有發(fā)現(xiàn)一個生活中的現(xiàn)象,我們很少有時間去真正讀一些存放在電腦或者ipad上的pdf書籍。我們打算讀這些書,但從來沒有讀過。所以我們?yōu)槭裁床挥肞ython把它們做成有聲書,一邊聽一邊做別的事情呢?

      我們計劃Python腳本步驟是這樣的:

      1. 允許用戶選擇讀取一個.pdf文件

      2. 將文件內(nèi)容轉(zhuǎn)換為一個字符串

      3. 輸出的mp3音頻文件

      允許用戶選擇讀取一個.pdf文件

      Python可以輕松地讀取文件。

      我只需要使用open(“filelocation”,“rb”)在讀取模式下打開文件。但我不想每次使用代碼時都要將文件復(fù)制并粘貼到代碼目錄中。因此,為了使它更容易,我們將使用tkinter庫來打開一個讓我們選擇文件的接口:

      from tkinter import Tkfrom tkinter.filedialog import askopenfilename
      Tk().withdraw() # we don't want a full GUI, so keep the root window from appearingfilelocation = askopenfilename() # open the dialog GUI

      太好了。現(xiàn)在,我們將文件位置存儲在filelocation變量中。

      將文件轉(zhuǎn)換為一個字符串


           

      如前所述,要在Python中打開文件,我們只需要使用open()方法。但是我們還希望將pdf文件轉(zhuǎn)換為常規(guī)文本。

      為此,我們將使用一個名為pdftotext的庫。

      先安裝:

      sudo pip install pdftotext

      然后:

      from tkinter import Tkfrom tkinter.filedialog import askopenfilenameimport pdftotext
      Tk().withdraw() # we don't want a full GUI, so keep the root window from appearingfilelocation = askopenfilename() # open the dialog GUI
      with open(filelocation, "rb") as f:  # open the file in reading (rb) mode and call it f    pdf = pdftotext.PDF(f)  # store a text version of the pdf file f in pdf variable

      如果您打印這個變量,您將得到一個字符串?dāng)?shù)組。每個字符串都是文件中的一行。要將它們?nèi)看鎯Φ揭粋€.mp3文件中,我們必須確保它們都存儲為一個字符串。讓我們循環(huán)這個數(shù)組并將它們?nèi)刻砑拥揭粋€字符串中:

      from tkinter import Tkfrom tkinter.filedialog import askopenfilenameimport pdftotext
      Tk().withdraw() # we don't want a full GUI, so keep the root window from appearingfilelocation = askopenfilename() # open the dialog GUI
      with open(filelocation, "rb") as f:  # open the file in reading (rb) mode and call it f    pdf = pdftotext.PDF(f)  # store a text version of the pdf file f in pdf variable
      string_of_text = ''for text in pdf:    string_of_text += text

      輸出.mp3文件


           

      現(xiàn)在,我們準(zhǔn)備使用gTTS(谷歌文本到語音)庫。我們所需要做的就是傳遞我們創(chuàng)建的字符串,將輸出存儲在一個變量中,然后使用save()方法將文件輸出到計算機(jī)。

      先安裝:

      sudo pip install gtts

      然后:

      from tkinter import Tkfrom tkinter.filedialog import askopenfilenameimport pdftotextfrom gtts import gTTS
      Tk().withdraw() # we don't want a full GUI, so keep the root window from appearingfilelocation = askopenfilename() # open the dialog GUI
      with open(filelocation, "rb") as f:  # open the file in reading (rb) mode and call it f    pdf = pdftotext.PDF(f)  # store a text version of the pdf file f in pdf variable
      string_of_text = ''for text in pdf:    string_of_text += text
      final_file = gTTS(text=string_of_text, lang='en')  # store file in variablefinal_file.save("Generated Speech.mp3")  # save file to computer

      就這么簡單!快去拿你的pdf去嘗試吧。

      以上就是如何利用Python將. pdf電子書籍轉(zhuǎn)換成音頻有聲讀物,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


      名稱欄目:如何利用Python將.pdf電子書籍轉(zhuǎn)換成音頻有聲讀物
      文章網(wǎng)址:http://www.ef60e0e.cn/article/ippjjo.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        虹口区| 马尔康县| 乃东县| 防城港市| 洛扎县| 新化县| 花垣县| 平山县| 土默特左旗| 灯塔市| 桂林市| 儋州市| 平武县| 申扎县| 延寿县| 伊金霍洛旗| 朝阳区| 从江县| 吉林省| 甘谷县| 伊川县| 花莲县| 浦东新区| 新泰市| 武胜县| 宁都县| 伊吾县| 阿荣旗| 江华| 武夷山市| 大悟县| 香河县| 万盛区| 永嘉县| 萝北县| 华坪县| 建德市| 通山县| 泗洪县| 沙湾县| 清远市|