podcast_tts adalah perpustakaan Python untuk menghasilkan podcast dan dialog menggunakan Text-to-Speech (TTS). Ini mendukung banyak speaker, musik latar, dan pencampuran audio yang tepat untuk hasil berkualitas profesional.
Anda dapat mendengarkan podcast contoh di bawah ini:
voices untuk penggunaan di masa mendatang. # ensure to have sox, or ffmpeg installed
brew install sox
# install the package
pip install podcast_tts import asyncio
from podcast_tts import PodcastTTS
async def main ():
tts = PodcastTTS ( speed = 5 )
await tts . generate_tts (
text = "Hello! Welcome to our podcast." ,
speaker = "male1" ,
filename = "output_audio.wav" ,
channel = "both"
)
if __name__ == "__main__" :
asyncio . run ( main ())Metode generate_podcast menggabungkan dialog dan musik latar untuk produksi podcast yang mulus.
import asyncio
from podcast_tts import PodcastTTS
async def main ():
tts = PodcastTTS ( speed = 5 )
# Define speakers and text
texts = [
{ "male1" : [ "Welcome to the podcast!" , "both" ]},
{ "female2" : [ "Today, we discuss AI advancements." , "left" ]},
{ "male2" : [ "Don't miss our exciting updates." , "right" ]},
]
# Define background music (local file or URL)
music_config = [ "https://example.com/background_music.mp3" , 10 , 3 , 0.3 ]
# Generate the podcast
output_file = await tts . generate_podcast (
texts = texts ,
music = music_config ,
filename = "podcast_with_music.mp3" ,
pause_duration = 0.5 ,
normalize = True
)
print ( f"Podcast saved to: { output_file } " )
if __name__ == "__main__" :
asyncio . run ( main ())Podcasttts termasuk profil speaker premade berikut:
Profil ini termasuk dalam direktori paket default_voices dan dapat digunakan tanpa pengaturan tambahan.
Ketika profil speaker ditentukan tetapi tidak ada, perpustakaan akan secara otomatis menghasilkan profil speaker baru dan menyimpannya di subfolder suara. Ini memastikan peran suara yang konsisten di berbagai putaran dalam dialog. Misalnya:
texts = [
{ "Narrator" : [ "Welcome to this exciting episode." , "left" ]},
{ "Expert" : [ "Today, we'll explore AI's impact on healthcare." , "right" ]},
]
# If "Narrator" or "Expert" profiles do not exist, they will be generated dynamically.Profil disimpan di direktori suara skrip dan digunakan kembali secara otomatis jika pembicara yang sama digunakan di masa depan untuk konsistensi.
Anda dapat memuat profil speaker apa pun dengan menentukan nama file (tanpa ekstensi .txt). Profil disimpan dalam subfolder suara, jadi Anda tidak perlu menentukan jalur secara eksplisit.
# Assuming a speaker profile "Host.txt" exists in the voices subfolder
await tts . generate_tts ( "This is a test for an existing speaker." , "Host" , "existing_speaker.wav" )Kontribusi dipersilakan! Jangan ragu untuk mengirimkan masalah atau menarik permintaan pada repositori GitHub.
Proyek ini dilisensikan di bawah lisensi MIT. Lihat file lisensi untuk detailnya.