Add pitch to Voice tag, eg 1F20 1M-20
Browse files
app.py
CHANGED
@@ -45,6 +45,7 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
45 |
#voice1F ="en-US-EmmaNeural - en-US (Female)"
|
46 |
voice1F ="en-GB-SoniaNeural - en-GB (Female)"
|
47 |
voice2 = "it-IT-GiuseppeMultilingualNeural - it-IT (Male)"
|
|
|
48 |
voice2F = "en-US-JennyNeural - en-US (Female)"
|
49 |
voice1 = "en-AU-WilliamNeural - en-AU (Male)"
|
50 |
voice3F = "en-HK-YanNeural - en-HK (Female)"
|
@@ -58,7 +59,13 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
58 |
silence_durations = []
|
59 |
parts = re.split(r'(SS\d+\.?\d*)', text)
|
60 |
for part in parts:
|
61 |
-
if re.
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
# At the top of your file:
|
63 |
#SILENCE_PATH = Path(__file__).parent.absolute() / "Silence.mp3"
|
64 |
# At the top of your file (assuming you uploaded "Silence.mp3" to root)
|
@@ -73,7 +80,6 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
73 |
print(f"Silence.mp3 file NOT FOUND")
|
74 |
silence_file_path = get_silence(silence_duration) # Store the returned filename
|
75 |
audio_segments.append(silence_file_path) # Use the stored filename
|
76 |
-
|
77 |
elif part.strip():
|
78 |
processed_text = part
|
79 |
current_voice = voice
|
@@ -112,6 +118,9 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
112 |
current_voice = (voice or default_voice).split(" - ")[0]
|
113 |
processed_text=part[:]
|
114 |
rate_str = f"{current_rate:+d}%"
|
|
|
|
|
|
|
115 |
pitch_str = f"{current_pitch:+d}Hz"
|
116 |
communicate = edge_tts.Communicate(processed_text, current_voice, rate=rate_str, pitch=pitch_str)
|
117 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
@@ -176,7 +185,7 @@ async def create_demo():
|
|
176 |
description = """
|
177 |
Default = male, other voices 1F:US_Emma, 2F:US_Jenny, 3F:HK_Yan, 1M:AU_Will, 2M:IT_Guiseppe,3M:US_Brian, 1C: Childvoice, 1O = OldMan
|
178 |
You can insert silence using the marker 'SS' (This will insert a Silence period from the Silence.mp3 file).
|
179 |
-
Enter your text, select a voice, and adjust the speech rate and pitch.
|
180 |
The application will process your text paragraph by paragraph (separated by two blank lines).
|
181 |
"""
|
182 |
|
|
|
45 |
#voice1F ="en-US-EmmaNeural - en-US (Female)"
|
46 |
voice1F ="en-GB-SoniaNeural - en-GB (Female)"
|
47 |
voice2 = "it-IT-GiuseppeMultilingualNeural - it-IT (Male)"
|
48 |
+
voice2 = "en-GB-RyanNeural - en-GB (Male)"
|
49 |
voice2F = "en-US-JennyNeural - en-US (Female)"
|
50 |
voice1 = "en-AU-WilliamNeural - en-AU (Male)"
|
51 |
voice3F = "en-HK-YanNeural - en-HK (Female)"
|
|
|
59 |
silence_durations = []
|
60 |
parts = re.split(r'(SS\d+\.?\d*)', text)
|
61 |
for part in parts:
|
62 |
+
if (re.search(r'-?\d+', part)): #if there are any digit following the voice tag, eg 1F20 or 1F-20
|
63 |
+
match = re.search(r'-?\d+', part)
|
64 |
+
pitch = match.group() #Set pitch to set value as noted in the tag
|
65 |
+
# Remove only the first integer found
|
66 |
+
part = re.sub(r'-?\d+', '', part1, count=1).strip() #cut out the pitch int from text part
|
67 |
+
|
68 |
+
if re.match(r'SS\d+\.?\d*', part): #Check if there is Silence tag
|
69 |
# At the top of your file:
|
70 |
#SILENCE_PATH = Path(__file__).parent.absolute() / "Silence.mp3"
|
71 |
# At the top of your file (assuming you uploaded "Silence.mp3" to root)
|
|
|
80 |
print(f"Silence.mp3 file NOT FOUND")
|
81 |
silence_file_path = get_silence(silence_duration) # Store the returned filename
|
82 |
audio_segments.append(silence_file_path) # Use the stored filename
|
|
|
83 |
elif part.strip():
|
84 |
processed_text = part
|
85 |
current_voice = voice
|
|
|
118 |
current_voice = (voice or default_voice).split(" - ")[0]
|
119 |
processed_text=part[:]
|
120 |
rate_str = f"{current_rate:+d}%"
|
121 |
+
if part[2:4].isdigit():
|
122 |
+
processed_text = part[4:]
|
123 |
+
pitch = int(part[2:4])
|
124 |
pitch_str = f"{current_pitch:+d}Hz"
|
125 |
communicate = edge_tts.Communicate(processed_text, current_voice, rate=rate_str, pitch=pitch_str)
|
126 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
|
|
185 |
description = """
|
186 |
Default = male, other voices 1F:US_Emma, 2F:US_Jenny, 3F:HK_Yan, 1M:AU_Will, 2M:IT_Guiseppe,3M:US_Brian, 1C: Childvoice, 1O = OldMan
|
187 |
You can insert silence using the marker 'SS' (This will insert a Silence period from the Silence.mp3 file).
|
188 |
+
Enter your text, select a voice, and adjust the speech rate and pitch. Can also set like 1F-20 or 1M24
|
189 |
The application will process your text paragraph by paragraph (separated by two blank lines).
|
190 |
"""
|
191 |
|