UNPKG

9.38 kBMarkdownView Raw
1[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
2[//]: # "To regenerate it, use `python -m synthtool`."
3<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
4
5# [Cloud Speech: Node.js Client](https://github.com/googleapis/nodejs-speech)
6
7[![release level](https://img.shields.io/badge/release%20level-stable-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
8[![npm version](https://img.shields.io/npm/v/@google-cloud/speech.svg)](https://www.npmjs.org/package/@google-cloud/speech)
9
10
11
12
13Cloud Speech Client Library for Node.js
14
15
16A comprehensive list of changes in each version may be found in
17[the CHANGELOG](https://github.com/googleapis/nodejs-speech/blob/main/CHANGELOG.md).
18
19* [Cloud Speech Node.js Client API Reference][client-docs]
20* [Cloud Speech Documentation][product-docs]
21* [github.com/googleapis/nodejs-speech](https://github.com/googleapis/nodejs-speech)
22
23Read more about the client libraries for Cloud APIs, including the older
24Google APIs Client Libraries, in [Client Libraries Explained][explained].
25
26[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
27
28**Table of contents:**
29
30
31* [Quickstart](#quickstart)
32 * [Before you begin](#before-you-begin)
33 * [Installing the client library](#installing-the-client-library)
34 * [Using the client library](#using-the-client-library)
35* [Samples](#samples)
36* [Versioning](#versioning)
37* [Contributing](#contributing)
38* [License](#license)
39
40## Quickstart
41
42### Before you begin
43
441. [Select or create a Cloud Platform project][projects].
451. [Enable the Cloud Speech API][enable_api].
461. [Set up authentication with a service account][auth] so you can access the
47 API from your local workstation.
48
49### Installing the client library
50
51```bash
52npm install @google-cloud/speech
53```
54
55
56### Using the client library
57
58```javascript
59// Imports the Google Cloud client library
60const speech = require('@google-cloud/speech');
61
62// Creates a client
63const client = new speech.SpeechClient();
64
65async function quickstart() {
66 // The path to the remote LINEAR16 file
67 const gcsUri = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw';
68
69 // The audio file's encoding, sample rate in hertz, and BCP-47 language code
70 const audio = {
71 uri: gcsUri,
72 };
73 const config = {
74 encoding: 'LINEAR16',
75 sampleRateHertz: 16000,
76 languageCode: 'en-US',
77 };
78 const request = {
79 audio: audio,
80 config: config,
81 };
82
83 // Detects speech in the audio file
84 const [response] = await client.recognize(request);
85 const transcription = response.results
86 .map(result => result.alternatives[0].transcript)
87 .join('\n');
88 console.log(`Transcription: ${transcription}`);
89}
90quickstart();
91
92```
93
94
95
96## Samples
97
98Samples are in the [`samples/`](https://github.com/googleapis/nodejs-speech/tree/main/samples) directory. Each sample's `README.md` has instructions for running its sample.
99
100| Sample | Source Code | Try it |
101| --------------------------- | --------------------------------- | ------ |
102| Microphone stream | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/MicrophoneStream.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/MicrophoneStream.js,samples/README.md) |
103| Beta Features | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/betaFeatures.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/betaFeatures.js,samples/README.md) |
104| Export-to-storage.v1p1beta1 | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/export-to-storage.v1p1beta1.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/export-to-storage.v1p1beta1.js,samples/README.md) |
105| Infinite Streaming | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/infiniteStreaming.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/infiniteStreaming.js,samples/README.md) |
106| Model Adaptation | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/modelAdaptation.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/modelAdaptation.js,samples/README.md) |
107| Multi Region | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/multiRegion.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/multiRegion.js,samples/README.md) |
108| Profanity Filter | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/profanityFilter.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/profanityFilter.js,samples/README.md) |
109| Quickstart | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
110| Recognize | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/recognize.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/recognize.js,samples/README.md) |
111| Recognize speech with metadata | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/recognize.v1p1beta1.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/recognize.v1p1beta1.js,samples/README.md) |
112| Transcribe Context Classes | [source code](https://github.com/googleapis/nodejs-speech/blob/main/samples/transcribeContextClasses.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/transcribeContextClasses.js,samples/README.md) |
113
114
115
116The [Cloud Speech Node.js Client API Reference][client-docs] documentation
117also contains samples.
118
119## Supported Node.js Versions
120
121Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/).
122Libraries are compatible with all current _active_ and _maintenance_ versions of
123Node.js.
124
125Client libraries targeting some end-of-life versions of Node.js are available, and
126can be installed via npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).
127The dist-tags follow the naming convention `legacy-(version)`.
128
129_Legacy Node.js versions are supported as a best effort:_
130
131* Legacy versions will not be tested in continuous integration.
132* Some security patches may not be able to be backported.
133* Dependencies will not be kept up-to-date, and features will not be backported.
134
135#### Legacy tags available
136
137* `legacy-8`: install client libraries from this dist-tag for versions
138 compatible with Node.js 8.
139
140## Versioning
141
142This library follows [Semantic Versioning](http://semver.org/).
143
144
145
146This library is considered to be **stable**. The code surface will not change in backwards-incompatible ways
147unless absolutely necessary (e.g. because of critical security issues) or with
148an extensive deprecation period. Issues and requests against **stable** libraries
149are addressed with the highest priority.
150
151
152
153
154
155
156More Information: [Google Cloud Platform Launch Stages][launch_stages]
157
158[launch_stages]: https://cloud.google.com/terms/launch-stages
159
160## Contributing
161
162Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-speech/blob/main/CONTRIBUTING.md).
163
164Please note that this `README.md`, the `samples/README.md`,
165and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`)
166are generated from a central template. To edit one of these files, make an edit
167to its templates in
168[directory](https://github.com/googleapis/synthtool).
169
170## License
171
172Apache Version 2.0
173
174See [LICENSE](https://github.com/googleapis/nodejs-speech/blob/main/LICENSE)
175
176[client-docs]: https://googleapis.dev/nodejs/speech/latest
177[product-docs]: https://cloud.google.com/speech-to-text/docs/
178[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
179[projects]: https://console.cloud.google.com/project
180[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
181[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=speech.googleapis.com
182[auth]: https://cloud.google.com/docs/authentication/getting-started