mirror of
https://github.com/hwchase17/langchain.git
synced 2025-04-29 04:16:02 +00:00
141 lines
3.8 KiB
Plaintext
141 lines
3.8 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "a991a6f8-1897-4f49-a191-ae3bdaeda856",
|
||
"metadata": {},
|
||
"source": [
|
||
"# Google Cloud Text-to-Speech\n",
|
||
"\n",
|
||
">[Google Cloud Text-to-Speech](https://cloud.google.com/text-to-speech) enables developers to synthesize natural-sounding speech with 100+ voices, available in multiple languages and variants. It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks to deliver the highest fidelity possible.\n",
|
||
">\n",
|
||
">It supports multiple languages, including English, German, Polish, Spanish, Italian, French, Portuguese, and Hindi.\n",
|
||
"\n",
|
||
"This notebook shows how to interact with the `Google Cloud Text-to-Speech API` to achieve speech synthesis capabilities."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "9eeb311e-e1bd-4959-8536-4d267f302eb3",
|
||
"metadata": {},
|
||
"source": [
|
||
"First, you need to set up an Google Cloud project. You can follow the instructions [here](https://cloud.google.com/text-to-speech/docs/before-you-begin)."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "0a309c0e-5310-4eaa-8af9-bcbc252e45da",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"!pip install --upgrade langchain-google-community[texttospeech]"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "5b86ad38-ac8a-4f0a-a492-01a6e3090c8c",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Instantiation"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 8,
|
||
"id": "e2efded2-894b-4683-89ed-2a6948913fa9",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-01T17:47:31.565221Z",
|
||
"iopub.status.busy": "2024-09-01T17:47:31.564804Z",
|
||
"iopub.status.idle": "2024-09-01T17:47:31.570600Z",
|
||
"shell.execute_reply": "2024-09-01T17:47:31.569764Z",
|
||
"shell.execute_reply.started": "2024-09-01T17:47:31.565188Z"
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"from langchain_google_community import TextToSpeechTool"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "434b2454-2bff-484d-822c-4026a9dc1383",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Deprecated GoogleCloudTextToSpeechTool"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 10,
|
||
"id": "2f57a647-9214-4562-a8cf-f263a15d1f40",
|
||
"metadata": {
|
||
"execution": {
|
||
"iopub.execute_input": "2024-09-01T17:51:28.763915Z",
|
||
"iopub.status.busy": "2024-09-01T17:51:28.763664Z",
|
||
"iopub.status.idle": "2024-09-01T17:51:28.779073Z",
|
||
"shell.execute_reply": "2024-09-01T17:51:28.778477Z",
|
||
"shell.execute_reply.started": "2024-09-01T17:51:28.763897Z"
|
||
}
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"from langchain_community.tools import GoogleCloudTextToSpeechTool"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "a2647bc5-e494-41f9-9f53-4a278ea30cc1",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"text_to_speak = \"Hello world!\"\n",
|
||
"\n",
|
||
"tts = GoogleCloudTextToSpeechTool()\n",
|
||
"tts.name"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "d4613fed-66f0-47c6-be50-7e7670654427",
|
||
"metadata": {},
|
||
"source": [
|
||
"We can generate audio, save it to the temporary file and then play it."
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 7,
|
||
"id": "f1984844-aa75-4f83-9d42-1c8052d87cc0",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"speech_file = tts.run(text_to_speak)"
|
||
]
|
||
}
|
||
],
|
||
"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.10.12"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|