UNPKG

9.68 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-general%20availability%20%28GA%29-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[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-speech/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-speech)
10
11
12
13
14Cloud Speech Client Library for Node.js
15
16
17A comprehensive list of changes in each version may be found in
18[the CHANGELOG](https://github.com/googleapis/nodejs-speech/blob/master/CHANGELOG.md).
19
20* [Cloud Speech Node.js Client API Reference][client-docs]
21* [Cloud Speech Documentation][product-docs]
22* [github.com/googleapis/nodejs-speech](https://github.com/googleapis/nodejs-speech)
23
24Read more about the client libraries for Cloud APIs, including the older
25Google APIs Client Libraries, in [Client Libraries Explained][explained].
26
27[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
28
29**Table of contents:**
30
31
32* [Quickstart](#quickstart)
33 * [Before you begin](#before-you-begin)
34 * [Installing the client library](#installing-the-client-library)
35 * [Using the client library](#using-the-client-library)
36* [Samples](#samples)
37* [Versioning](#versioning)
38* [Contributing](#contributing)
39* [License](#license)
40
41## Quickstart
42
43### Before you begin
44
451. [Select or create a Cloud Platform project][projects].
461. [Enable the Cloud Speech API][enable_api].
471. [Set up authentication with a service account][auth] so you can access the
48 API from your local workstation.
49
50### Installing the client library
51
52```bash
53npm install @google-cloud/speech
54```
55
56
57### Using the client library
58
59```javascript
60// Imports the Google Cloud client library
61const speech = require('@google-cloud/speech');
62
63// Creates a client
64const client = new speech.SpeechClient();
65
66async function quickstart() {
67 // The path to the remote LINEAR16 file
68 const gcsUri = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw';
69
70 // The audio file's encoding, sample rate in hertz, and BCP-47 language code
71 const audio = {
72 uri: gcsUri,
73 };
74 const config = {
75 encoding: 'LINEAR16',
76 sampleRateHertz: 16000,
77 languageCode: 'en-US',
78 };
79 const request = {
80 audio: audio,
81 config: config,
82 };
83
84 // Detects speech in the audio file
85 const [response] = await client.recognize(request);
86 const transcription = response.results
87 .map(result => result.alternatives[0].transcript)
88 .join('\n');
89 console.log(`Transcription: ${transcription}`);
90}
91quickstart();
92
93```
94
95
96
97## Samples
98
99Samples are in the [`samples/`](https://github.com/googleapis/nodejs-speech/tree/master/samples) directory. Each sample's `README.md` has instructions for running its sample.
100
101| Sample | Source Code | Try it |
102| --------------------------- | --------------------------------- | ------ |
103| Microphone stream | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
104| Beta Features | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
105| Export-to-storage.v1p1beta1 | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
106| Infinite Streaming | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
107| Model Adaptation | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
108| Multi Region | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
109| Profanity Filter | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
110| Quickstart | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
111| Recognize | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
112| Recognize speech with metadata | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
113| Transcribe Context Classes | [source code](https://github.com/googleapis/nodejs-speech/blob/master/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) |
114
115
116
117The [Cloud Speech Node.js Client API Reference][client-docs] documentation
118also contains samples.
119
120## Supported Node.js Versions
121
122Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/).
123Libraries are compatible with all current _active_ and _maintenance_ versions of
124Node.js.
125
126Client libraries targeting some end-of-life versions of Node.js are available, and
127can be installed via npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).
128The dist-tags follow the naming convention `legacy-(version)`.
129
130_Legacy Node.js versions are supported as a best effort:_
131
132* Legacy versions will not be tested in continuous integration.
133* Some security patches may not be able to be backported.
134* Dependencies will not be kept up-to-date, and features will not be backported.
135
136#### Legacy tags available
137
138* `legacy-8`: install client libraries from this dist-tag for versions
139 compatible with Node.js 8.
140
141## Versioning
142
143This library follows [Semantic Versioning](http://semver.org/).
144
145
146This library is considered to be **General Availability (GA)**. This means it
147is stable; the code surface will not change in backwards-incompatible ways
148unless absolutely necessary (e.g. because of critical security issues) or with
149an extensive deprecation period. Issues and requests against **GA** libraries
150are addressed with the highest priority.
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/master/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 template in this
168[directory](https://github.com/googleapis/synthtool/tree/master/synthtool/gcp/templates/node_library).
169
170## License
171
172Apache Version 2.0
173
174See [LICENSE](https://github.com/googleapis/nodejs-speech/blob/master/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