keep updated
This commit is contained in:
82
1000-hours/public/jupyter-notebooks/sentence-openai.ipynb
Normal file
82
1000-hours/public/jupyter-notebooks/sentence-openai.ipynb
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "e6525deb-267c-475f-a73a-7939c5bdca86",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/var/folders/k_/t1vf2gd95jbc1j3k49xxdfy80000gn/T/ipykernel_17239/1823463615.py:29: 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": [
|
||||
"from openai import OpenAI\n",
|
||||
"import IPython\n",
|
||||
"from datetime import datetime\n",
|
||||
"import sys\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"import os\n",
|
||||
"\n",
|
||||
"load_dotenv()\n",
|
||||
"client = OpenAI(\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"text = \"\"\"\n",
|
||||
"People's opinions vary from individual to individual.\n",
|
||||
"\"\"\"\n",
|
||||
"# Create audios for each versions (three was set as default previously.)\n",
|
||||
"\n",
|
||||
"for v in [\"alloy\", \"nova\"]:\n",
|
||||
" # alloy, echo, fable, onyx, nova, and shimmer, the last two of which are femail voices.\n",
|
||||
" \n",
|
||||
" speech_file_path = f'sentence-{text.split(\" \")[1]}-{text.split(\" \")[2]}-{v}.mp3'\n",
|
||||
" \n",
|
||||
" rspd_audio = client.audio.speech.create(\n",
|
||||
" model=\"tts-1\",\n",
|
||||
" voice=v,\n",
|
||||
" input=text\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" rspd_audio.stream_to_file(speech_file_path)\n",
|
||||
" \n",
|
||||
" # IPython.display.Audio(speech_file_path)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "603fb48b-2fd5-482c-9c96-38a65fc43824",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.1"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user