Skip to content

Commit

Permalink
Remove pitch option as it no longer has any effect
Browse files Browse the repository at this point in the history
* Most likely Microsoft started ignoring it along with the custom SSML
  purge
  • Loading branch information
rany2 committed Jan 5, 2023
1 parent 01c87b7 commit 4862ec8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 4 additions & 9 deletions src/edge_tts/communicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -146,7 +146,7 @@ def mkssml(

ssml = (
"<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>"
f"<voice name='{voice}'><prosody pitch='{pitch}' rate='{rate}' volume='{volume}'>"
f"<voice name='{voice}'><prosody pitch='+0Hz' rate='{rate}' volume='{volume}'>"
f"{text}</prosody></voice></speak>"
)
return ssml
Expand Down Expand Up @@ -197,7 +197,6 @@ def __init__(
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,
Expand Down Expand Up @@ -231,10 +230,6 @@ def __init__(
):
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
Expand All @@ -254,7 +249,7 @@ async def stream(self) -> AsyncGenerator[Dict[str, Any], None]:
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
Expand Down Expand Up @@ -321,7 +316,7 @@ async def stream(self) -> AsyncGenerator[Dict[str, Any], None]:
connect_id(),
date,
mkssml(
text, self.voice, self.pitch, self.rate, self.volume
text, self.voice, self.rate, self.volume
),
)
)
Expand Down
6 changes: 0 additions & 6 deletions src/edge_tts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4862ec8

Please sign in to comment.