From 4862ec85176a9abb90d269f5a45afd10732955ae Mon Sep 17 00:00:00 2001 From: rany2 Date: Thu, 5 Jan 2023 03:12:48 +0200 Subject: [PATCH] Remove pitch option as it no longer has any effect * Most likely Microsoft started ignoring it along with the custom SSML purge --- README.md | 9 +++++---- src/edge_tts/communicate.py | 13 ++++--------- src/edge_tts/util.py | 6 ------ 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 8ebb045..db4dd83 100644 --- a/README.md +++ b/README.md @@ -63,17 +63,18 @@ You must first check the available voices with the `--list-voices` option: Support for custom SSML has been removed since 5.0.0 because Microsoft has taken the initiative to prevent it from working. You cannot use custom SSML anymore. -### Changing pitch, rate, volume, etc. +### Changing rate, volume, etc. It is possible to make minor changes to the generated speech. - $ edge-tts --pitch=-10Hz --text "Hello, world!" --write-media hello_with_pitch_down.mp3 $ edge-tts --rate=-50% --text "Hello, world!" --write-media hello_with_rate_halved.mp3 $ edge-tts --volume=-50% --text "Hello, world!" --write-media hello_with_volume_halved.mp3 -Keep in mind that the `--pitch`, `--rate`, `--volume`, etc. options are applied to the entire SSML document. +Keep in mind that the `--rate`, `--volume`, etc. options are applied to the entire SSML document. -In addition, it is required to use `--pitch=-10Hz` instead of `--pitch -10Hz` otherwise the `-10Hz` would be interpreted as just another argument. +In addition, it is required to use `--rate=-50%` instead of `--pitch -50%` otherwise the `-50%` would be interpreted as just another argument. + +**NOTE**: `--pitch` was removed in 6.0.3 as it no longer appears to have any effect. ### Note on the `edge-playback` command diff --git a/src/edge_tts/communicate.py b/src/edge_tts/communicate.py index fe8f95f..f31690e 100644 --- a/src/edge_tts/communicate.py +++ b/src/edge_tts/communicate.py @@ -133,7 +133,7 @@ def split_text_by_byte_length(text: Union[str, bytes], byte_length: int) -> List def mkssml( - text: Union[str, bytes], voice: str, pitch: str, rate: str, volume: str + text: Union[str, bytes], voice: str, rate: str, volume: str ) -> str: """ Creates a SSML string from the given parameters. @@ -146,7 +146,7 @@ def mkssml( ssml = ( "" - f"" + f"" f"{text}" ) return ssml @@ -197,7 +197,6 @@ class Communicate: text: str, voice: str = "Microsoft Server Speech Text to Speech Voice (en-US, AriaNeural)", *, - pitch: str = "+0Hz", rate: str = "+0%", volume: str = "+0%", proxy: Optional[str] = None, @@ -231,10 +230,6 @@ class Communicate: ): raise ValueError(f"Invalid voice '{voice}'.") - if re.match(r"^[+-]?\d+Hz$", pitch) is None: - raise ValueError(f"Invalid pitch '{pitch}'.") - self.pitch: str = pitch - if re.match(r"^[+-]?\d+%$", rate) is None: raise ValueError(f"Invalid rate '{rate}'.") self.rate: str = rate @@ -254,7 +249,7 @@ class Communicate: ssml_headers_plus_data( connect_id(), date_to_string(), - mkssml("", self.voice, self.pitch, self.rate, self.volume), + mkssml("", self.voice, self.rate, self.volume), ) ) + 50 # margin of error @@ -321,7 +316,7 @@ class Communicate: connect_id(), date, mkssml( - text, self.voice, self.pitch, self.rate, self.volume + text, self.voice, self.rate, self.volume ), ) ) diff --git a/src/edge_tts/util.py b/src/edge_tts/util.py index 571ff37..df570f3 100644 --- a/src/edge_tts/util.py +++ b/src/edge_tts/util.py @@ -83,12 +83,6 @@ async def _async_main() -> None: help="lists available voices", action="store_true", ) - parser.add_argument( - "-p", - "--pitch", - help="set TTS pitch. Default +0Hz, For more info check https://bit.ly/3eAE5Nx", - default="+0Hz", - ) parser.add_argument( "-r", "--rate",