docs: fix the ImportError in google_speech_to_text.ipynb (#26522)

fix #26370

- #26370 

`GoogleSpeechToTextLoader` is a deprecated method in
`langchain_community.document_loaders.google_speech_to_text`.

The new recommended usage is to use `SpeechToTextLoader` from
`langchain_google_community`.

When importing from `langchain_google_community`, use the name
`SpeechToTextLoader` instead of the old `GoogleSpeechToTextLoader`.


![image](https://github.com/user-attachments/assets/3a8bd309-9858-4938-b7db-872f51b9542e)

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
gbaian10 2024-09-18 06:18:57 +08:00 committed by GitHub
parent 418b170f94
commit 6fe2536c5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@
"source": [ "source": [
"# Google Speech-to-Text Audio Transcripts\n", "# Google Speech-to-Text Audio Transcripts\n",
"\n", "\n",
"The `GoogleSpeechToTextLoader` allows to transcribe audio files with the [Google Cloud Speech-to-Text API](https://cloud.google.com/speech-to-text) and loads the transcribed text into documents.\n", "The `SpeechToTextLoader` allows to transcribe audio files with the [Google Cloud Speech-to-Text API](https://cloud.google.com/speech-to-text) and loads the transcribed text into documents.\n",
"\n", "\n",
"To use it, you should have the `google-cloud-speech` python package installed, and a Google Cloud project with the [Speech-to-Text API enabled](https://cloud.google.com/speech-to-text/v2/docs/transcribe-client-libraries#before_you_begin).\n", "To use it, you should have the `google-cloud-speech` python package installed, and a Google Cloud project with the [Speech-to-Text API enabled](https://cloud.google.com/speech-to-text/v2/docs/transcribe-client-libraries#before_you_begin).\n",
"\n", "\n",
@ -41,7 +41,7 @@
"source": [ "source": [
"## Example\n", "## Example\n",
"\n", "\n",
"The `GoogleSpeechToTextLoader` must include the `project_id` and `file_path` arguments. Audio files can be specified as a Google Cloud Storage URI (`gs://...`) or a local file path.\n", "The `SpeechToTextLoader` must include the `project_id` and `file_path` arguments. Audio files can be specified as a Google Cloud Storage URI (`gs://...`) or a local file path.\n",
"\n", "\n",
"Only synchronous requests are supported by the loader, which has a [limit of 60 seconds or 10MB](https://cloud.google.com/speech-to-text/v2/docs/sync-recognize#:~:text=60%20seconds%20and/or%2010%20MB) per audio file." "Only synchronous requests are supported by the loader, which has a [limit of 60 seconds or 10MB](https://cloud.google.com/speech-to-text/v2/docs/sync-recognize#:~:text=60%20seconds%20and/or%2010%20MB) per audio file."
] ]
@ -52,13 +52,13 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from langchain_google_community import GoogleSpeechToTextLoader\n", "from langchain_google_community import SpeechToTextLoader\n",
"\n", "\n",
"project_id = \"<PROJECT_ID>\"\n", "project_id = \"<PROJECT_ID>\"\n",
"file_path = \"gs://cloud-samples-data/speech/audio.flac\"\n", "file_path = \"gs://cloud-samples-data/speech/audio.flac\"\n",
"# or a local file path: file_path = \"./audio.wav\"\n", "# or a local file path: file_path = \"./audio.wav\"\n",
"\n", "\n",
"loader = GoogleSpeechToTextLoader(project_id=project_id, file_path=file_path)\n", "loader = SpeechToTextLoader(project_id=project_id, file_path=file_path)\n",
"\n", "\n",
"docs = loader.load()" "docs = loader.load()"
] ]
@ -152,7 +152,7 @@
" RecognitionConfig,\n", " RecognitionConfig,\n",
" RecognitionFeatures,\n", " RecognitionFeatures,\n",
")\n", ")\n",
"from langchain_google_community import GoogleSpeechToTextLoader\n", "from langchain_google_community import SpeechToTextLoader\n",
"\n", "\n",
"project_id = \"<PROJECT_ID>\"\n", "project_id = \"<PROJECT_ID>\"\n",
"location = \"global\"\n", "location = \"global\"\n",
@ -171,7 +171,7 @@
" ),\n", " ),\n",
")\n", ")\n",
"\n", "\n",
"loader = GoogleSpeechToTextLoader(\n", "loader = SpeechToTextLoader(\n",
" project_id=project_id,\n", " project_id=project_id,\n",
" location=location,\n", " location=location,\n",
" recognizer_id=recognizer_id,\n", " recognizer_id=recognizer_id,\n",