1000-hours/public/jupyter-notebooks/edge-tts.ipynb
https://github.com/rany2/edge-tts
edge-tts is a Python module that allows you to use Microsoft Edge's online text-to-speech service from within your Python code or using the provided edge-tts or edge-playback command.
!pip install edge-tts
!pip install pygame
import asyncio
import edge_tts
import pygame
TEXT = """
The young artist painted a stunning landscape with a barn and a vast sky.
"""
# VOICE = "zh-CN-YunxiaNeural"
# VOICE = "en-IN-PrabhatNeural"
# VOICE = "zh-CN-liaoning-XiaobeiNeural"
VOICE = "en-US-GuyNeural" # Male
# VOICE = "en-US-AnaNeural" # Female
# VOICE = "en-US-AndrewNeural" # Male
# VOICE = "en-US-AriaNeural" # Female
# VOICE = "en-US-AvaNeural" # Female
# VOICE = "en-US-BrianNeural" # Male
# VOICE = "en-US-ChristopherNeural" # Male
# VOICE = "en-US-EmmaNeural" # Female
# VOICE = "en-US-EricNeural" # Male
# VOICE = "en-US-GuyNeural" # Male
# VOICE = "en-US-JennyNeural" # Female
# VOICE = "en-US-MichelleNeural" # Female
# VOICE = "en-US-RogerNeural" # Male
# VOICE = "en-US-SteffanNeural" # Male
# VOICE = "en-GB-LibbyNeural" # Female
# VOICE = "en-GB-MaisieNeural" # Female
# VOICE = "en-GB-RyanNeural" # Male
# VOICE = "en-GB-SoniaNeural" # Female
# VOICE = "en-GB-ThomasNeural" # Male
# VOICE = "en-AU-NatashaNeural" # Female
# VOICE = "en-AU-WilliamNeural" # Male
# VOICE = "en-CA-ClaraNeural" # Female
# VOICE = "en-CA-LiamNeural" # Male
OUTPUT_FILE_NAME = f"{VOICE}_{TEXT[:15]}.mp3"
OUTPUT_FILE = f"{OUTPUT_FILE_NAME}.mp3"
WEBVTT_FILE = f"{OUTPUT_FILE_NAME}.vtt"
communicate = edge_tts.Communicate(TEXT, VOICE)
await communicate.save(OUTPUT_FILE)
submaker = edge_tts.SubMaker()
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":
submaker.create_sub((chunk["offset"], chunk["duration"]), chunk["text"])
with open(WEBVTT_FILE, "w", encoding="utf-8") as file:
file.write(submaker.generate_subs())
print("Files created!")
pygame.mixer.init()
pygame.mixer.music.load(OUTPUT_FILE)
pygame.mixer.music.play()
%pip install amfm_decompy
import amfm_decompy.basic_tools as basic
import amfm_decompy.pYAAPT as pYAAPT
import matplotlib.pyplot as plt
import numpy as np
#load audio 注意必须是wav
signal = basic.SignalObj("/Users/joker/Desktop/Speaking Training/The Case Against Education/Clips/Chapter 01 (Selection) 01.wav")
#pYAAPT pitches 生成pitches文件
pitch = pYAAPT.yaapt(signal, frame_length = 40, tda_frame_length=40,f0_min=75, f0_max=600)
#plot
plt.plot(pitch.samp_values)
plt.show()
edge_tts.list_voices()
import os
print(os.getcwd())