@@ -31,8 +31,8 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
31
31
* [ Quickstart] ( #quickstart )
32
32
* [ Before you begin] ( #before-you-begin )
33
33
* [ Installing the client library] ( #installing-the-client-library )
34
- * [ Using the client library ] ( #using-the-client-library )
35
- * [ Samples ] ( #samples )
34
+
35
+
36
36
* [ Versioning] ( #versioning )
37
37
* [ Contributing] ( #contributing )
38
38
* [ License] ( #license )
@@ -54,94 +54,6 @@ npm install @google-cloud/media-translation
54
54
```
55
55
56
56
57
- ### Using the client library
58
-
59
- ``` javascript
60
- const fs = require (' fs' );
61
-
62
- // Imports the CLoud Media Translation client library
63
- const {
64
- SpeechTranslationServiceClient ,
65
- } = require (' @google-cloud/media-translation' );
66
-
67
- // Creates a client
68
- const client = new SpeechTranslationServiceClient ();
69
-
70
- async function quickstart () {
71
- /**
72
- * TODO(developer): Uncomment the following lines before running the sample.
73
- */
74
- // const filename = 'Local path to audio file, e.g. /path/to/audio.raw';
75
- // const encoding = 'Encoding of the audio file, e.g. LINEAR16';
76
- // const sourceLanguage = 'BCP-47 source language code, e.g. en-US';
77
- // const targetLanguage = 'BCP-47 target language code, e.g. es-ES';
78
-
79
- const config = {
80
- audioConfig: {
81
- audioEncoding: encoding,
82
- sourceLanguageCode: sourceLanguage,
83
- targetLanguageCode: targetLanguage,
84
- },
85
- };
86
-
87
- // First request needs to have only a streaming config, no data.
88
- const initialRequest = {
89
- streamingConfig: config,
90
- audioContent: null ,
91
- };
92
-
93
- const readStream = fs .createReadStream (filename, {
94
- highWaterMark: 4096 ,
95
- encoding: ' base64' ,
96
- });
97
-
98
- const chunks = [];
99
- readStream
100
- .on (' data' , chunk => {
101
- const request = {
102
- streamingConfig: config,
103
- audioContent: chunk .toString (),
104
- };
105
- chunks .push (request);
106
- })
107
- .on (' close' , () => {
108
- // Config-only request should be first in stream of requests
109
- stream .write (initialRequest);
110
- for (let i = 0 ; i < chunks .length ; i++ ) {
111
- stream .write (chunks[i]);
112
- }
113
- stream .end ();
114
- });
115
-
116
- const stream = client .streamingTranslateSpeech ().on (' data' , response => {
117
- const {result } = response;
118
- if (result .textTranslationResult .isFinal ) {
119
- console .log (
120
- ` \n Final translation: ${ result .textTranslationResult .translation } `
121
- );
122
- console .log (` Final recognition result: ${ result .recognitionResult } ` );
123
- } else {
124
- console .log (
125
- ` \n Partial translation: ${ result .textTranslationResult .translation } `
126
- );
127
- console .log (` Partial recognition result: ${ result .recognitionResult } ` );
128
- }
129
- });
130
-
131
-
132
- ` ` `
133
-
134
-
135
-
136
- ## Samples
137
-
138
- Samples are in the [` samples/ ` ](https://github.com/googleapis/nodejs-media-translation/tree/main/samples) directory. Each sample's ` README .md ` has instructions for running its sample.
139
-
140
- | Sample | Source Code | Try it |
141
- | --------------------------- | --------------------------------- | ------ |
142
- | Quickstart | [source code](https://github.com/googleapis/nodejs-media-translation/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-media-translation&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
143
- | Translate_from_file | [source code](https://github.com/googleapis/nodejs-media-translation/blob/main/samples/translate_from_file.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-media-translation&page=editor&open_in_editor=samples/translate_from_file.js,samples/README.md) |
144
- | Translate_from_mic | [source code](https://github.com/googleapis/nodejs-media-translation/blob/main/samples/translate_from_mic.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-media-translation&page=editor&open_in_editor=samples/translate_from_mic.js,samples/README.md) |
145
57
146
58
147
59
0 commit comments