1 / 6

Computer Speech Synthesis with Python

Learn how to make your computer speak in different languages, create temporary audio files, and automate text-to-speech using Python. Install gTTS and Pygame libraries, generate speech, and play audio files. Enhance your coding skills with this helpful guide.

thomasv
Download Presentation

Computer Speech Synthesis with Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Python 語音介紹

  2. 如何讓電腦說話 ? • 安裝 gTTS功能套件 pip install gTTS from gtts import gTTS tts=gTTS(text=“Hello?”,lang=“en”) tts.save(“hello.mp3”)

  3. 如何讓電腦說中文話 ? from gtts import gTTS tts=gTTS(text=“你好嗎?”,lang=“zh-tw”) tts.save(“hello.mp3”)

  4. 如何讓電腦主動說話 ? • 安裝 pygame功能套件 pip install pygame from pygame import mixer mixer.init() mixer.music.load(“hello.mp3”) mixer.music.play()

  5. 如何讓電腦隨機產生暫存檔? from gtts import gTTS from pygame import mixer import tempfile with tempfile.NamedTemporaryFile(delete=True) as fp: tts=gTTS(text="今天,你好嗎?",lang="zh-tw") tts.save("{}.mp3".format(fp.name)) mixer.init() mixer.music.load("{}.mp3".format(fp.name)) mixer.music.play()

  6. 如何可以重複使用電腦語音播放 ? from gtts import gTTS from pygame import mixer import tempfile defspeak(sentence): with tempfile.NamedTemporaryFile(delete=True) as fp: tts=gTTS(text=sentence,lang="zh-tw") tts.save("{}.mp3".format(fp.name)) mixer.init() mixer.music.load("{}.mp3".format(fp.name)) mixer.music.play() speak("學習過程是痛苦的,但成果是甜美的")

More Related