95 lines
3.3 KiB
Plaintext
95 lines
3.3 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"#gTTS语音\n",
|
|
"from gtts import gTTS\n",
|
|
"#engine = pyttsx3.init('espeak')\n",
|
|
"tts = gTTS(text=\"军士上前,将英玉兰架起,英玉兰被举下\",lang='zh-cn')\n",
|
|
"#engine.save_to_file(\"欢迎使用百度语音合成,本次测试为Python接口\",'./test')\n",
|
|
"tts.save(\"./test.mp3\")\n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2021-11-09T07:21:49.711270Z",
|
|
"iopub.status.busy": "2021-11-09T07:21:49.709862Z",
|
|
"iopub.status.idle": "2021-11-09T07:21:50.010690Z",
|
|
"shell.execute_reply": "2021-11-09T07:21:50.007394Z",
|
|
"shell.execute_reply.started": "2021-11-09T07:21:49.711004Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"ename": "ModuleNotFoundError",
|
|
"evalue": "No module named 'aip'",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
|
"\u001b[0;32m<ipython-input-1-3dd6f47059b1>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m#百度语音在线\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0maip\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mAipSpeech\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\"\"\" 你的 APPID AK SK \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mAPP_ID\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'17553946'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
|
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'aip'"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"#百度语音在线\n",
|
|
"from aip import AipSpeech\n",
|
|
"\n",
|
|
"\"\"\" 你的 APPID AK SK \"\"\"\n",
|
|
"APP_ID = '17553946'\n",
|
|
"API_KEY = 'i5LBXalkBn2KHTqdifesA1EB'\n",
|
|
"SECRET_KEY = '1ktP6qDH7nMFHjotRdKpnI13w41Bvk59'\n",
|
|
"\n",
|
|
"client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)\n",
|
|
"\n",
|
|
"result = client.synthesis('军士上前,将英玉兰架起,英玉兰被举下。', 'zh', 5, {\n",
|
|
" 'vol': 5,'per': 4,\n",
|
|
"})\n",
|
|
"\n",
|
|
"# 识别正确返回语音二进制 错误则返回dict 参照下面错误码\n",
|
|
"if not isinstance(result, dict):\n",
|
|
" with open('./test3.mp3', 'wb') as f:\n",
|
|
" f.write(result)\n",
|
|
"else:print(result)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"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.8.10"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|