08-21-1355, chapter 4.3-group

This commit is contained in:
xiaolai
2024-08-21 13:55:33 +08:00
parent c8947459e3
commit 162e7e3edf
14 changed files with 123 additions and 27 deletions

View File

@@ -29,7 +29,7 @@
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": 2,
"id": "71d35cd9",
"metadata": {},
"outputs": [
@@ -37,19 +37,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"['en-US-GuyNeural', 'en-US-AriaNeural']\n",
"hello\n",
"../audios/hello-us-male.mp3 created\n",
"../audios/hello-us-female.mp3 created\n",
"\n",
"heat\n",
"../audios/heat-us-male.mp3 created\n",
"../audios/heat-us-female.mp3 created\n",
"\n",
"high\n",
"../audios/high-us-male.mp3 created\n",
"../audios/high-us-female.mp3 created\n",
"\n"
"pygame 2.6.0 (SDL 2.28.4, Python 3.12.2)\n",
"Hello from the pygame community. https://www.pygame.org/contribute.html\n"
]
}
],
@@ -84,10 +73,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "4146f92e",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['en-US-GuyNeural', 'en-US-AriaNeural']\n",
"apple\n",
"../audios/apple-us-male.mp3 exists, skipping...\n",
"../audios/apple-us-female.mp3 exists, skipping...\n",
"\n",
"impossible\n",
"../audios/impossible-us-male.mp3 exists, skipping...\n",
"../audios/impossible-us-female.mp3 exists, skipping...\n",
"\n",
"possible\n",
"../audios/possible-us-male.mp3 created\n",
"../audios/possible-us-female.mp3 created\n",
"\n",
"ichthyosaur\n",
"../audios/ichthyosaur-us-male.mp3 created\n",
"../audios/ichthyosaur-us-female.mp3 created\n",
"\n"
]
}
],
"source": [
"\n",
"voices = [\"en-US-GuyNeural\", \"en-US-AriaNeural\", \"en-GB-RyanNeural\", \"en-GB-LibbyNeural\"]\n",
@@ -101,9 +114,11 @@
" print(voices)\n",
"\n",
"words = \"\"\"\n",
"hello,\n",
"heat,\n",
"high,\n",
"apple,\n",
"impossible,\n",
"possible,\n",
"ichthyosaur,\n",
"\n",
"\"\"\"\n",
"\n",
"for word in words.strip().split(','):\n",
@@ -117,10 +132,18 @@
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": 15,
"id": "2d46cde4",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a-woman--without-her--man-is-nothing_openai.mp3\n"
]
}
],
"source": [
"def get_openai_tts_audio(text, path, performer='alloy'):\n",
" \n",
@@ -137,12 +160,14 @@
" ) as response:\n",
" response.stream_to_file(path)\n",
" \n",
"sentence = \"The explanation you gave was clear but I need a more detailed explanation.\"\n",
"sentence = \"A woman..., without her..., man is nothing.\"\n",
"\n",
"# remove all punctuation at the end of sentence,\n",
"# replace all spaces and punctuations in the sentence with dash\n",
"audio_filename_openai = sentence.translate(str.maketrans(' ,.?!', '-----')).strip().replace(\"--\", \"-\") + '_openai.mp3'\n",
"audio_filename_msedge = sentence.translate(str.maketrans(' ,.?!', '-----')).strip().replace(\"--\", \"-\") + '_msedge.mp3'\n",
"audio_filename_openai = sentence.strip().translate(str.maketrans(',.?! ', '-----')).replace(\"--\", \"-\").lower().rstrip('-') + '_openai.mp3'\n",
"audio_filename_msedge = sentence.strip().translate(str.maketrans(',.?! ', '-----')).replace(\"--\", \"-\").lower().rstrip('-') + '_msedge.mp3'\n",
"\n",
"print(audio_filename_openai)\n",
"# get_openai_tts_audio(sentence, audio_filename_openai, performer='alloy')\n",
"# await generate_edge_tts_audio(sentence, audio_filename_msedge, voice=\"en-US-GuyNeural\", verbose=True, overwrite=True, play=True)\n",
"\n",