343 lines
12 KiB
Plaintext
343 lines
12 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f330d08f-fa3c-4cf4-bf53-136be20393e9",
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Install or update openai modules \n",
|
|
"%pip install openai\n",
|
|
"# %pip install --upgrade openai"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "71ad2e48-3b33-42d3-8e4c-9f89c61110de",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Load Modules\n",
|
|
"from openai import OpenAI\n",
|
|
"import IPython\n",
|
|
"from datetime import datetime"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a1a72146-6815-49b2-b516-3177a69470f2",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"client = OpenAI(\n",
|
|
" # replace openai api key below (which is invalid) with your own\n",
|
|
" api_key=\"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\" \n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2066aba4-cdc1-4c27-8d6b-a902cab3e184",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"role_definition = \"\"\"\n",
|
|
"你是我的英语教练。\n",
|
|
"请将我的话改写成英文。\n",
|
|
"不需要逐字翻译。\n",
|
|
"请分析清楚我的内容,而后用英文重新逻辑清晰地组织它。\n",
|
|
"请使用地道的美式英语,纽约腔调。\n",
|
|
"请尽量使用日常词汇,尽量优先使用短语动词或者习惯用语。\n",
|
|
"每个句子最长不应该超过 20 个单词。\n",
|
|
"\"\"\"\n",
|
|
"\n",
|
|
"user_prompt = \"\"\"\n",
|
|
"人们对高管、首席执行官或庞大业务部门的领导者有不一样的憧憬。\n",
|
|
"他们认为,在那个级别的每个人都有足够的经验和智慧,至少看起来知道自己在做什么。\n",
|
|
"他们假定那里有深思熟虑、战略和长远思考,以及握手言和的合理交易。\n",
|
|
"但有些时候,它是高中;甚至有些时候,它是幼儿园。\n",
|
|
"\"\"\"\n",
|
|
"\n",
|
|
"# how many versions needed.\n",
|
|
"number_of_choices = 3\n",
|
|
"\n",
|
|
"# your openai subscription might not support gpt-4...\n",
|
|
"# gpt-3.5 is ok too.\n",
|
|
"rspd_translation = client.chat.completions.create(\n",
|
|
" model=\"gpt-4\",\n",
|
|
" messages=[\n",
|
|
" {\n",
|
|
" \"role\": \"system\", \n",
|
|
" \"content\": role_definition\n",
|
|
" },\n",
|
|
" {\n",
|
|
" \"role\": \"user\", \n",
|
|
" \"content\": user_prompt\n",
|
|
" }\n",
|
|
" ],\n",
|
|
" n = number_of_choices \n",
|
|
")\n",
|
|
"\n",
|
|
"for rspd in rspd_translation.choices:\n",
|
|
" print(f\"{rspd.index+1}.\\n{rspd.message.content}\\n\\n\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4a92f81f-fe8d-4cc8-a770-13ea1e12259f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Create audios for each versions (three was set as default previously.)\n",
|
|
"\n",
|
|
"voice_performer = \"alloy\"\n",
|
|
"# alloy, echo, fable, onyx, nova, and shimmer, the last two of which are femail voices.\n",
|
|
"\n",
|
|
"for i in range(number_of_choices):\n",
|
|
" speech_file_path = f'{datetime.now().strftime(\"%Y%m%d_%H%M%S\")}_speech.mp3'\n",
|
|
" \n",
|
|
" rspd_audio = client.audio.speech.create(\n",
|
|
" model=\"tts-1\",\n",
|
|
" voice=voice_performer,\n",
|
|
" input=rspd_translation.choices[i].message.content\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": "d28f1714-bdbe-4f29-b52c-56a07af6d60e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Or else, you could rewrite your own version for open ai tts\n",
|
|
"your_version = \"\"\"\n",
|
|
"Let's look at both ends of the spectrum. On one end, we see the physical decline of the majority... and on the other? A group is gaining strength through exercise, a feat impossible for our ancestors.\n",
|
|
"\n",
|
|
"Most modern people, perhaps top 20%, can only manage more than 10 push-ups. Our ancestors might have been stronger, but how many of them could do 100 push-ups? Can you guess the world record? In 1980, Minoru Yoshida of Japan did 10,507. In 1993, Charles Servizio of the US did 46,001 in just over 21 hours...\n",
|
|
"\n",
|
|
"Physical limits are constantly being pushed, and although still a small percentage, more and more people are getting stronger.\n",
|
|
"\n",
|
|
"The 1908 Olympic marathon record was 2 hours, 55 minutes, 18 seconds. Today, it's around 2 hours, 2 minutes, 57 seconds, shaving off over 50 minutes, that is, 30% reduction of time. More than a hundred years ago, only one person could run 2 hours, 55 minutes, 18 seconds; few could even manage 3 hours and 5 minites. Nowadays, each year, around 30,000 people are eligible to participate in the Boston Marathon because they can run faster than the minimum qualifying time of 3 hours 5 minutes.\n",
|
|
"\n",
|
|
"These are the impacts the Industrial Revolution had on human physical fitness:\n",
|
|
"\n",
|
|
"More people are becoming physically weaker (e.g., from 20% to 90%) \n",
|
|
"\n",
|
|
"Fewer people are exercising (e.g., from 20% to 10%) \n",
|
|
"\n",
|
|
"But, of those exercising, more are seeing better results (e.g., from 20% of 20% to 80% of 10%) \n",
|
|
"\n",
|
|
"The best results among exercisers were unimaginable before (e.g., 46,000 push-ups) \n",
|
|
"\n",
|
|
"The gap between first and second place keeps widening, and it's quite shocking (e.g., second place might only manage 20,000 push-ups)\n",
|
|
"\n",
|
|
"Let's ponder for a moment, how the sudden emergence and rapid development of artificial intelligence might impact our mental capabilities?\n",
|
|
"\n",
|
|
"Just as the Industrial Revolution gradually lessened the physical demands on humans for survival, our cognitive needs are also continuously decreasing. The universal biological principle of \"use it or lose it\" is constantly shaping our brains.\n",
|
|
"\n",
|
|
"This isn't specific to the age of AI, it's a trend that's been ongoing for years. One of the reasons why consumer society has greatly advanced in the past few decades is because of the widespread application of idiot-proof design principle - products or services designed to be used with no prior learning or thinking, so that they're ready-to-use, making them potential bestsellers.\n",
|
|
"\n",
|
|
"Now, this trend is being exponentially amplified by AI, which makes learning easier than ever before. Even if learning or thinking becomes necessary, AI has made it less demanding, thus significantly reducing the costs of both. \"Use it or lose it\" becomes \"use only if necessary, discard if not.\"\n",
|
|
"\n",
|
|
"Therefore, the general impact of AI on our intellectual abilities parallels, if not matches, the effect the Industrial Revolution had on our physical strength.\n",
|
|
"\n",
|
|
"More people are becoming mentally weaker\n",
|
|
"\n",
|
|
"Fewer people are exercising\n",
|
|
"\n",
|
|
"But, of those exercising, more are seeing better results\n",
|
|
"\n",
|
|
"The best results among exercisers were unimaginable before\n",
|
|
"\n",
|
|
"The gap between first and second place keeps widening, and it'd be much more shocking\n",
|
|
"\"\"\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4696c0dc-8983-475b-b376-ec0f059cffa8",
|
|
"metadata": {},
|
|
"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",
|
|
"\n",
|
|
"voice_performer = \"echo\"\n",
|
|
"# alloy, echo, fable, onyx, nova, and shimmer, the last two of which are femail voices.\n",
|
|
"\n",
|
|
"rspd_audio = client.audio.speech.create(\n",
|
|
" model=\"tts-1\",\n",
|
|
" voice=voice_performer,\n",
|
|
" input=your_version\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": "2c52f66b-acc0-46ec-9d7d-326c86387e55",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"wordlist = your_version.split()\n",
|
|
"print(wordlist)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "30514938-5810-4017-acb6-07521fe7e4a1",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"for p in ['alloy', 'nova']:\n",
|
|
" for i in range(3): \n",
|
|
" for w in wordlist:\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\"ə-{wordlist.index(w) + 1}-{voice_performer}-{w}-0{i}.mp3\"\n",
|
|
" rspd_audio.stream_to_file(speech_file_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "ddd8a182-c5fd-4266-9a24-ecea13fb3207",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "472eb5e1-5215-4523-997c-68817f02cc57",
|
|
"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": {
|
|
"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
|
|
}
|