Additional comments and refinements

This commit is contained in:
Edward Donner
2024-12-22 10:30:50 +00:00
parent 747473ebfe
commit 26f1135ead
7 changed files with 119 additions and 170 deletions

View File

@@ -366,7 +366,7 @@
"id": "d91d3f8f-e505-4e3c-a87c-9e42ed823db6",
"metadata": {},
"source": [
"# For Mac users\n",
"# For Mac users - and possibly many PC users too\n",
"\n",
"This version should work fine for you. It might work for Windows users too, but you might get a Permissions error writing to a temp file. If so, see the next section!\n",
"\n",
@@ -410,19 +410,56 @@
"id": "ad89a9bd-bb1e-4bbb-a49a-83af5f500c24",
"metadata": {},
"source": [
"# For Windows users\n",
"# For Windows users (or any Mac users with problems above)\n",
"\n",
"## First try the Mac version above, but if you get a permissions error writing to a temp file, then this code should work instead.\n",
"\n",
"A collaboration between students Mark M. and Patrick H. and Claude got this resolved!\n",
"\n",
"Below are 3 variations - hopefully one of them will work on your PC. If not, message me please!\n",
"Below are 4 variations - hopefully one of them will work on your PC. If not, message me please!\n",
"\n",
"And for Mac people - all 3 of the below work on my Mac too - please try these if the Mac version gave you problems.\n",
"\n",
"## PC Variation 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d104b96a-02ca-4159-82fe-88e0452aa479",
"metadata": {},
"outputs": [],
"source": [
"import base64\n",
"from io import BytesIO\n",
"from PIL import Image\n",
"from IPython.display import Audio, display\n",
"\n",
"def talker(message):\n",
" response = openai.audio.speech.create(\n",
" model=\"tts-1\",\n",
" voice=\"onyx\",\n",
" input=message)\n",
"\n",
" audio_stream = BytesIO(response.content)\n",
" output_filename = \"output_audio.mp3\"\n",
" with open(output_filename, \"wb\") as f:\n",
" f.write(audio_stream.read())\n",
"\n",
" # Play the generated audio\n",
" display(Audio(output_filename, autoplay=True))\n",
"\n",
"talker(\"Well, hi there\")"
]
},
{
"cell_type": "markdown",
"id": "3a5d11f4-bbd3-43a1-904d-f684eb5f3e3a",
"metadata": {},
"source": [
"## PC Variation 2"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -473,7 +510,7 @@
"id": "96f90e35-f71e-468e-afea-07b98f74dbcf",
"metadata": {},
"source": [
"## PC Variation 2"
"## PC Variation 3"
]
},
{
@@ -516,7 +553,7 @@
"id": "e821224c-b069-4f9b-9535-c15fdb0e411c",
"metadata": {},
"source": [
"## PC Variation 3\n",
"## PC Variation 4\n",
"\n",
"### Let's try a completely different sound library\n",
"\n",
@@ -577,7 +614,7 @@
"id": "7986176b-cd04-495f-a47f-e057b0e462ed",
"metadata": {},
"source": [
"## PC Users - if none of those 3 variations worked!\n",
"## PC Users - if none of those 4 variations worked!\n",
"\n",
"Please get in touch with me. I'm sorry this is causing problems! We'll figure it out.\n",
"\n",