標籤

bat (52) 作品 (38) python (21) shell (17) windows (11) 虛擬機 (11) php (10) CPP (6) KMS (6) 程式設計 (6) docker (5) 使用教學 (5) xoops (4) 公文 (4) Apache2 (3) Excel (3) juniper (3) 資料庫 (3) mysql (2) 免動手 (2) 資料結構 (2) 軟體廣播 (2) 電腦維修 (2) Android Studio (1) Apple IPAD管理 (1) Arduino (1) CSS (1) LAMP (1) NAS (1) Ubuntu (1) VHD (1) Windows Server (1) 原因 (1) 程式應用 (1) 程式積木 (1) 編輯器 (1) 雲端硬碟 (1)

2022年7月11日 星期一

回答問題:將程式碼中 zh 改成 en 與測試文字稿改成英文,會不會有問題?

系列文章:

        由於網友提出問題。我將其截圖如下:
這讓我很好奇,到底是哪出了問題。於是,我將程式碼由 zh 改成 en。然後將測試文字檔改為英文。然後將修改後的程式碼編譯成EXE,方便使用。
       測試結果:
發現沒有問題。我的測試環境為作業系統:Windows 10 64位元 Python 版本:3.9.0。 那接下來可能是版本問題。
       最後完成程式:
下載檔案。解壓密碼:demo1234
教學影片:
       以下是程式原始碼的內容:
程式目的:讀取Txt.txt 將之轉成merge.mp3
程式名稱:Txt2Mp3Python.py
程式內容:
from gtts import gTTS
import os

mp3_path=str(os.path.abspath(os.getcwd()))+'\\mp3\\'
i = 0
merge_file = list()
# 一行一行地讀取Txt.txt,轉成 001.mp3 002.mp3 003.mp3 ...
TxtFileName = 'Txt.txt'
with open(TxtFileName) as f:
    for line in f.readlines():
        i=i+1
        myobj = gTTS(text=line, lang='en', slow=True)
        myobj.save(mp3_path+str(i).zfill(3)+'.mp3')
        merge_file.append(mp3_path+str(i).zfill(3)+'.mp3')

merge_file_mp3 = list()
# mp3資料夾內mp3 合併成 merge.mp3
for j in merge_file:
    with open(j,'rb') as f:
        merge_file_mp3.append(f.read())

with open('merge.mp3','wb') as f:
    for j in merge_file_mp3:
        f.write(j)

文字稿名稱:Txt.txt
文字稿內容:
  Good afternoon,ladies and gentlemen!
  I’m very honored to stand here and give you a short speech! To begin with ,I want to ask a question .Does everybody dream a good dream last night Actually ,today I want to talk about dream with you. Of course, What I want to talk is not a dream you have last night,but a dream—— about life.
  Everyone has dreams about life, different dreams at different life stage,and we need dreams to support us. Dreams are like the stars we never reach in the sky,but like most mariners,we can chart our course by them. With the dream,we have a direction,with a direction, we were no longer confused.With the dream, there is hope,With hope, we have the strength to fight.
  But I know,life is tough,and there are always ups and downs, maybe we fail in the way to our aims,and we may feel depressed ,whenever at this time, the dream in our heart can always comfort us, encourage us ,and support us to move ahead.

資料來源:

文字檔資料來源:

沒有留言:

張貼留言

只要點兩下,傳統右鍵選單改回Win11右鍵選單

系列文章: 1. 只要點兩下,就能將Win11 右鍵選單 回復 傳統右鍵選單 2. 只要點兩下,傳統右鍵選單改回Win11右鍵選單 上一篇提到只要點兩下,就能將Win11選單回到傳統選單。但是有沒有方法能夠回到Win11選單呢?                    ...