欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python調(diào)用edge-tts實(shí)現(xiàn)在線文字轉(zhuǎn)語音效果

 更新時(shí)間:2024年03月08日 10:59:33   作者:培根芝士  
edge-tts是一個(gè) Python 模塊,允許通過Python代碼或命令的方式使用 Microsoft Edge 的在線文本轉(zhuǎn)語音服務(wù),這篇文章主要介紹了Python調(diào)用edge-tts實(shí)現(xiàn)在線文字轉(zhuǎn)語音效果,需要的朋友可以參考下

edge-tts是一個(gè) Python 模塊,允許通過Python代碼或命令的方式使用 Microsoft Edge 的在線文本轉(zhuǎn)語音服務(wù)。

項(xiàng)目源碼

GitHub - rany2/edge-tts: Use Microsoft Edge's online text-to-speech service from Python WITHOUT needing Microsoft Edge or Windows or an API keyUse Microsoft Edge's online text-to-speech service from Python WITHOUT needing Microsoft Edge or Windows or an API key - rany2/edge-tts

https://github.com/rany2/edge-tts

安裝

pip install edge-tts

用法

命令行方式

  • --write-media:輸出音頻
  • --write-subtitles:輸出字幕
edge-tts --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.vtt

選項(xiàng)檢查可用的聲音

edge-tts --list-voices

改變聲音

--voice:指定聲音

edge-tts --voice zh-CN-XiaoxiaoNeural --text "君不見黃河之水天上來" --write-media hello.mp3 --write-subtitles hello.vtt

改變速率、音量和音高

edge-tts --rate=-50% --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.vtt
edge-tts --volume=-50% --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.vtt
edge-tts --pitch=-50Hz --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.vtt

播放音頻

edge-playback

edge-playback 用于播放生成的語音。它采用與 edge-tts 相同的參數(shù)。

Python代碼方式

文字轉(zhuǎn)音頻

import asyncio
import edge_tts
TEXT = "Hello World!"
VOICE = "en-GB-SoniaNeural"
OUTPUT_FILE = "test.mp3"
async def amain() -> None:
    """Main function"""
    communicate = edge_tts.Communicate(TEXT, VOICE)
    await communicate.save(OUTPUT_FILE)
if __name__ == "__main__":
    loop = asyncio.get_event_loop_policy().get_event_loop()
    try:
        loop.run_until_complete(amain())
    finally:
        loop.close()

使用VoicesManager進(jìn)行動(dòng)態(tài)語音選擇的示例

import asyncio
import random
import edge_tts
from edge_tts import VoicesManager
TEXT = "Hoy es un buen día."
OUTPUT_FILE = "spanish.mp3"
async def amain() -> None:
    """Main function"""
    voices = await VoicesManager.create()
    voice = voices.find(Gender="Male", Language="es")
    # Also supports Locales
    # voice = voices.find(Gender="Female", Locale="es-AR")
    communicate = edge_tts.Communicate(TEXT, random.choice(voice)["Name"])
    await communicate.save(OUTPUT_FILE)
if __name__ == "__main__":
    loop = asyncio.get_event_loop_policy().get_event_loop()
    try:
        loop.run_until_complete(amain())
    finally:
        loop.close()

流式傳輸來自TTS的音頻數(shù)據(jù)

import asyncio
import edge_tts
TEXT = "Hello World!"
VOICE = "en-GB-SoniaNeural"
OUTPUT_FILE = "test.mp3"
async def amain() -> None:
    """Main function"""
    communicate = edge_tts.Communicate(TEXT, VOICE)
    with open(OUTPUT_FILE, "wb") as file:
        async for chunk in communicate.stream():
            if chunk["type"] == "audio":
                file.write(chunk["data"])
            elif chunk["type"] == "WordBoundary":
                print(f"WordBoundary: {chunk}")
if __name__ == "__main__":
    loop = asyncio.get_event_loop_policy().get_event_loop()
    try:
        loop.run_until_complete(amain())
    finally:
        loop.close()

到此這篇關(guān)于Python調(diào)用edge-tts實(shí)現(xiàn)在線文字轉(zhuǎn)語音的文章就介紹到這了,更多相關(guān)Python在線文字轉(zhuǎn)語音內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python中處理Session和Cookie的方法

    Python中處理Session和Cookie的方法

    這篇文章主要介紹了Python中處理Session和Cookie的方法,本文介紹了Python中如何處理Session和Cookie,包括獲取、設(shè)置、刪除和使用Session和Cookie的相關(guān)方法和技巧,主要涉及Python的requests、http.cookiejar和Flask等庫和框架
    2023-05-05
  • Python獲取文件所在目錄和文件名的方法

    Python獲取文件所在目錄和文件名的方法

    下面小編就為大家?guī)硪黄狿ython獲取文件所在目錄和文件名的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01
  • Python 可視化matplotlib模塊基礎(chǔ)知識(shí)

    Python 可視化matplotlib模塊基礎(chǔ)知識(shí)

    這篇文章主要給大家分享的是Python 可視化matplotlib模塊基礎(chǔ)知識(shí),文章對(duì)matplotlib.pyplot 模塊繪制相關(guān)如折線、柱狀、散點(diǎn)、圓餅圖表進(jìn)行簡(jiǎn)單地學(xué)習(xí),具有一定的參考價(jià)值,需要的朋友可以參考一下
    2021-12-12
  • Python腳本實(shí)現(xiàn)音頻和視頻格式轉(zhuǎn)換

    Python腳本實(shí)現(xiàn)音頻和視頻格式轉(zhuǎn)換

    這篇文章主要為大家詳細(xì)介紹了Python如何通過腳本實(shí)現(xiàn)音頻和視頻格式轉(zhuǎn)換,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-03-03
  • Python連接Kingbase的實(shí)現(xiàn)示例

    Python連接Kingbase的實(shí)現(xiàn)示例

    Kingbase是一種開源的數(shù)據(jù)庫管理系統(tǒng),與Oracle數(shù)據(jù)庫的語法和功能非常相似,本文主要介紹了Python連接Kingbase的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-12-12
  • python + winrm 實(shí)現(xiàn)遠(yuǎn)程連接Windows服務(wù)器并執(zhí)行指定命令的操作過程

    python + winrm 實(shí)現(xiàn)遠(yuǎn)程連接Windows服務(wù)器并執(zhí)行指定命令的操作過程

    Windows遠(yuǎn)程管理(WinRM)是Windows Server 2003 R2,Windows Vista和Windows Server 2008中一種新式的方便遠(yuǎn)程管理的服務(wù),這篇文章主要介紹了python + winrm 實(shí)現(xiàn)遠(yuǎn)程連接Windows服務(wù)器并執(zhí)行指定命令的操作過程,需要的朋友可以參考下
    2023-10-10
  • Python基礎(chǔ)學(xué)習(xí)之奇異的GUI對(duì)話框

    Python基礎(chǔ)學(xué)習(xí)之奇異的GUI對(duì)話框

    今天跨進(jìn)了GUI編程的園地,才發(fā)現(xiàn)python語言是這么的好玩,文中對(duì)GUI對(duì)話框作了非常詳細(xì)的介紹,對(duì)正在學(xué)習(xí)python的小伙伴們有很好的幫助,需要的朋友可以參考下
    2021-05-05
  • Python第三方庫之OpenCV庫的實(shí)用指南

    Python第三方庫之OpenCV庫的實(shí)用指南

    OpenCV(Open Source Computer Vision Library)作為一個(gè)強(qiáng)大的計(jì)算機(jī)視覺庫,提供了豐富的圖像處理和計(jì)算機(jī)視覺功能,本文將帶領(lǐng)讀者使用Python編程語言,通過簡(jiǎn)單的代碼示例,初步掌握OpenCV的圖像處理技術(shù),需要的朋友可以參考下
    2024-09-09
  • pygame實(shí)現(xiàn)俄羅斯方塊游戲(AI篇1)

    pygame實(shí)現(xiàn)俄羅斯方塊游戲(AI篇1)

    這篇文章主要為大家詳細(xì)介紹了pygame實(shí)現(xiàn)俄羅斯方塊游戲AI的第1篇,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • Python中使用第三方庫xlrd來讀取Excel示例

    Python中使用第三方庫xlrd來讀取Excel示例

    這篇文章主要介紹了Python中使用第三方庫xlrd來讀取Excel示例,本文講解了安裝xlrd、xlrd的API、使用xlrd讀取Excel代碼示例,需要的朋友可以參考下
    2015-04-04

最新評(píng)論