From 1df5639390e2e634b3a134010727ac3f09db0812 Mon Sep 17 00:00:00 2001 From: xiaolai Date: Sun, 24 Mar 2024 14:38:19 +0800 Subject: [PATCH] keep updated --- .../daily-speech-practice.ipynb | 117 +++++++++++++----- 1 file changed, 85 insertions(+), 32 deletions(-) diff --git a/1000-hours/public/jupyter-notebooks/daily-speech-practice.ipynb b/1000-hours/public/jupyter-notebooks/daily-speech-practice.ipynb index 40db7c46..63a7e9b3 100644 --- a/1000-hours/public/jupyter-notebooks/daily-speech-practice.ipynb +++ b/1000-hours/public/jupyter-notebooks/daily-speech-practice.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "71ad2e48-3b33-42d3-8e4c-9f89c61110de", "metadata": {}, "outputs": [], @@ -29,7 +29,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "a1a72146-6815-49b2-b516-3177a69470f2", "metadata": {}, "outputs": [], @@ -116,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "d28f1714-bdbe-4f29-b52c-56a07af6d60e", "metadata": {}, "outputs": [], @@ -167,37 +167,10 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "4696c0dc-8983-475b-b376-ec0f059cffa8", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/k_/t1vf2gd95jbc1j3k49xxdfy80000gn/T/ipykernel_26477/1091993583.py:13: DeprecationWarning: Due to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used instead\n", - " rspd_audio.stream_to_file(speech_file_path)\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# Create the audio of your version\n", "speech_file_path = f'{datetime.now().strftime(\"%Y%m%d_%H%M%S\")}_speech.mp3'\n", @@ -263,6 +236,86 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "44b9b94d-338d-43c9-84d6-1153439b5e0e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "f7800e33-64f7-49d4-b08f-778b0667fc18", + "metadata": {}, + "outputs": [], + "source": [ + "from openai import OpenAI\n", + "from dotenv import load_dotenv\n", + "\n", + "load_dotenv()\n", + "client = OpenAI(\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "fb3e96f3-e753-492a-9ae2-69905bbbbf6a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['cup', 'father', 'head', 'hat', 'above', 'mother', 'bird', 'sheep', 'ship', 'horse', 'blue', 'foot', 'day', 'eye', 'boy', 'nose', 'mouth', 'ear', 'hair', 'pure', 'fire', 'hour', 'pen', 'book', 'town', 'cutting', 'day', 'cat', 'give', 'fish', 'very', 'say', 'zoo', 'think', 'this', 'she', 'vision', 'hand', 'cheese', 'jump', 'moon', 'name', 'sing', 'look', 'run', 'we', 'yes']\n" + ] + } + ], + "source": [ + "wordlist = \"\"\"cup,father,head,hat,above,mother,bird,sheep,ship,horse,blue,foot,day,eye,boy,nose,mouth,ear,hair,pure,fire,hour,pen,book,town,cutting,day,cat,give,fish,very,say,zoo,think,this,she,vision,hand,cheese,jump,moon,name,sing,look,run,we,yes\"\"\"\n", + "words = wordlist.strip().split(',')\n", + "print(words)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "49eebe8f-de09-47bf-8c7d-f7c610b2bec1", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/k_/t1vf2gd95jbc1j3k49xxdfy80000gn/T/ipykernel_75584/4012291107.py:11: DeprecationWarning: Due to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used instead\n", + " rspd_audio.stream_to_file(speech_file_path)\n" + ] + } + ], + "source": [ + "for p in ['alloy', 'nova']:\n", + " for w in words:\n", + " voice_performer = p\n", + " # alloy, echo, fable, onyx, nova, and shimmer, the last two of which are femail voices.\n", + " rspd_audio = client.audio.speech.create(\n", + " model=\"tts-1\",\n", + " voice=voice_performer,\n", + " input=w\n", + " )\n", + " speech_file_path = f\"{w}-us-{\"male\" if p==\"alloy\" else \"female\"}.mp3\"\n", + " rspd_audio.stream_to_file(speech_file_path)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e6525deb-267c-475f-a73a-7939c5bdca86", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {