Skip to content
Closed
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
69f3f8d
feat!: initial library generation (#1)
Mar 19, 2020
64e6f05
chore: release 1.0.0 (#4)
release-please[bot] Mar 24, 2020
335dffa
feat: adds media translation file, mic samples
telpirion Mar 24, 2020
f63a098
feat!: drop node8 support (#17)
alexander-fenster Apr 2, 2020
30737b0
chore: release 2.0.0 (#18)
release-please[bot] Apr 7, 2020
6105674
feat: adds 'single_utterance' to stream from file sample (#20)
telpirion Apr 13, 2020
44735a0
fix: streaming mic sample
telpirion May 27, 2020
42f65d9
docs: update product doc links
yoshi-automation Jun 4, 2020
aa35da3
chore: release 2.1.0 (#27)
release-please[bot] Jun 4, 2020
1834906
chore(deps): update dependency mocha to v8 (#49)
renovate-bot Jun 11, 2020
8919a11
feat(samples): demonstrate real-time conversation translation (#48)
telpirion Jun 16, 2020
00de739
chore: release 2.2.0 (#47)
release-please[bot] Jun 29, 2020
839ce1e
chore: release 2.2.1 (#95)
release-please[bot] Nov 12, 2020
8e1a4ae
chore: release 2.2.2 (#98)
release-please[bot] Dec 2, 2020
5bf13e2
fix: Added check to see if stream has been destroyed before writing r…
awoehler Feb 3, 2021
d8a640a
chore: release 2.2.3 (#109)
release-please[bot] Mar 2, 2021
b3ff86b
samples: fixes a typo (#154)
telpirion Jun 18, 2021
289c718
samples: another typo in comments (#155)
telpirion Jun 22, 2021
6eb239f
chore: release 2.3.0 (#159)
release-please[bot] Jun 25, 2021
1619b04
chore: release 2.3.1 (#163)
release-please[bot] Jun 30, 2021
5584347
chore: release 2.3.2 (#165)
release-please[bot] Jul 12, 2021
3ae815c
chore: release 2.3.3 (#167)
release-please[bot] Jul 21, 2021
c5e3942
chore: release 2.3.4 (#175)
release-please[bot] Aug 17, 2021
1a45e25
fix(build): update branch to main (#180)
Sep 8, 2021
22989cc
chore: release 2.4.0 (#177)
release-please[bot] Sep 8, 2021
ebad8ee
build!: update library to use Node 12 (#225)
sofisl May 18, 2022
6693369
chore(main): release 3.0.0 (#227)
release-please[bot] Jun 20, 2022
0fd886e
chore(main): release 3.0.1 (#234)
release-please[bot] Jun 30, 2022
b7854e0
chore(main): release 3.0.2 (#245)
release-please[bot] Aug 26, 2022
8504a3a
chore(main): release 3.0.3 (#250)
release-please[bot] Sep 7, 2022
9ca42ab
chore(main): release 3.0.4 (#252)
release-please[bot] Sep 22, 2022
e38ae31
Merge remote-tracking branch 'migration/main' into nodejs-media-trans…
kweinmeister Nov 7, 2022
6b2ac1e
add CI workflow
kweinmeister Nov 7, 2022
9d31fe5
test: update CI workflow
kweinmeister Nov 7, 2022
44892f8
switch order of checkout and auth workflow
sofisl Nov 7, 2022
a63de94
switch order of workflow
sofisl Nov 7, 2022
2fa150f
fix indent
kweinmeister Nov 7, 2022
e151e9e
Merge branch 'main' into nodejs-media-translation-migration
kweinmeister Nov 7, 2022
b3c8b08
update CODEOWNERS
kweinmeister Nov 7, 2022
56f1e0d
update README
kweinmeister Nov 7, 2022
64d1041
update README typo
kweinmeister Nov 7, 2022
cebe6ce
change to mediatranslation
kweinmeister Nov 7, 2022
6e5cba4
reconcile region tags
kweinmeister Nov 7, 2022
7da2096
Merge branch 'main' into nodejs-media-translation-migration
kweinmeister Nov 8, 2022
12a882a
Merge branch 'main' into nodejs-media-translation-migration
kweinmeister Nov 8, 2022
3ed8efe
fix indent
kweinmeister Nov 7, 2022
48d1e7e
update CODEOWNERS
kweinmeister Nov 7, 2022
1da745a
change to mediatranslation
kweinmeister Nov 7, 2022
b264b90
Merge branch 'main' into nodejs-media-translation-migration
kweinmeister Nov 8, 2022
63f9827
use existing region tags
kweinmeister Nov 8, 2022
61d3ae0
revert change due to snippetbot check
kweinmeister Nov 8, 2022
f5521db
test: update CI workflow
kweinmeister Nov 7, 2022
961d3b2
change to mediatranslation
kweinmeister Nov 7, 2022
96aed15
test: update CI workflow
kweinmeister Nov 7, 2022
7d30df7
fix indent
kweinmeister Nov 7, 2022
91026a8
change to mediatranslation
kweinmeister Nov 7, 2022
61c2ba4
fix indent
kweinmeister Nov 7, 2022
3aa2c94
update CODEOWNERS
kweinmeister Nov 7, 2022
a255942
test: update CI workflow
kweinmeister Nov 7, 2022
2bad7e3
change to mediatranslation
kweinmeister Nov 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/media-translation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: mediatranslation
on:
push:
branches:
- main
paths:
- "mediatranslation/**"
pull_request:
paths:
- "mediatranslation/**"
pull_request_target:
types: [labeled]
schedule:
- cron: "0 0 * * 0"
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: "write"
pull-requests: "write"
id-token: "write"
steps:
- uses: actions/[email protected]
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- uses: "google-github-actions/[email protected]"
with:
workload_identity_provider: "projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider"
service_account: "[email protected]"
create_credentials_file: "true"
access_token_lifetime: 600s
- uses: actions/[email protected]
with:
node-version: 16
- run: npm install
working-directory: mediatranslation
- run: npm test
working-directory: mediatranslation
env:
MOCHA_REPORTER_SUITENAME: media_translation
MOCHA_REPORTER_OUTPUT: media_translation_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
- if: ${{ github.event_name == 'schedule'}}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"healthcare/dicom",
"healthcare/fhir",
"healthcare/hl7v2",
"mediatranslation",
"monitoring/opencensus",
"monitoring/prometheus",
"datacatalog/cloud-client",
Expand Down
3 changes: 3 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ cloud-tasks @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-r
workflows @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers
eventarc @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers

# Data & AI
mediatranslation @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers

# Other functions samples
functions/scheduleinstance @askmeegs @GoogleCloudPlatform/nodejs-samples-reviewers
functions/speech-to-speech @ricalo @GoogleCloudPlatform/nodejs-samples-reviewers
Expand Down
84 changes: 84 additions & 0 deletions mediatranslation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<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"/>

# [Cloud Media Translation: Node.js Samples](https://github.com/GoogleCloudPlatform/nodejs-docs-samples)

[![Open in Cloud Shell][shell_img]][shell_link]



## Table of Contents

- [Cloud Media Translation: Node.js Samples](#cloud-mediatranslation-nodejs-samples)
- [Table of Contents](#table-of-contents)
- [Before you begin](#before-you-begin)
- [Samples](#samples)
- [Quickstart](#quickstart)
- [Translate_from_file](#translate_from_file)
- [Translate_from_mic](#translate_from_mic)

## Before you begin

Before running the samples, make sure you've followed the steps outlined in
[Using the client library](https://github.com/googleapis/nodejs-media-translation#using-the-client-library).

`npm install`

`cd ..`

## Samples



### Quickstart

View the [source code](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/mediatranslation/quickstart.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/nodejs-docs-samples&page=editor&open_in_editor=mediatranslation/quickstart.js,mediatranslation/README.md)

__Usage:__


`node quickstart.js`


-----




### Translate_from_file

View the [source code](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/mediatranslation/translate_from_file.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/nodejs-docs-samples&page=editor&open_in_editor=mediatranslation/translate_from_file.js,mediatranslation/README.md)

__Usage:__


`node translate_from_file.js`


-----




### Translate_from_mic

View the [source code](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/mediatranslation/translate_from_mic.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/nodejs-docs-samples&page=editor&open_in_editor=mediatranslation/translate_from_mic.js,mediatranslation/README.md)

__Usage:__


`node translate_from_mic.js`






[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/nodejs-docs-samples&page=editor&open_in_editor=mediatranslation/README.md
[product-docs]: https://cloud.google.com/translate/media/docs/
24 changes: 24 additions & 0 deletions mediatranslation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "mediatranslation-samples",
"private": true,
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=12.0.0"
},
"files": [
"*.js"
],
"scripts": {
"test": "c8 mocha --timeout 600000 test/*.js"
},
"dependencies": {
"@google-cloud/media-translation": "^3.0.4",
"node-record-lpcm16": "1.0.1"
},
"devDependencies": {
"c8": "^7.0.0",
"chai": "^4.2.0",
"mocha": "^8.0.0"
}
}
101 changes: 101 additions & 0 deletions mediatranslation/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2020, Google LLC.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

/**
* Translate text from an audio file.
* @param {string} filename local path to
* @param {string} encoding the encoding of the audio rate, e.g. Linear16
* @param {string} sourceLanguage language translating from, as BCP-47 code
* @param {string} targetLanguage languate translating to, as BCP-47 code
*/
function main(filename, encoding, sourceLanguage, targetLanguage) {
// [START mediatranslation_quickstart]
const fs = require('fs');

// Imports the Cloud Media Translation client library
const {
SpeechTranslationServiceClient,
} = require('@google-cloud/media-translation');

// Creates a client
const client = new SpeechTranslationServiceClient();

async function quickstart() {
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const filename = 'Local path to audio file, e.g. /path/to/audio.raw';
// const encoding = 'Encoding of the audio file, e.g. LINEAR16';
// const sourceLanguage = 'BCP-47 source language code, e.g. en-US';
// const targetLanguage = 'BCP-47 target language code, e.g. es-ES';

const config = {
audioConfig: {
audioEncoding: encoding,
sourceLanguageCode: sourceLanguage,
targetLanguageCode: targetLanguage,
},
};

// First request needs to have only a streaming config, no data.
const initialRequest = {
streamingConfig: config,
audioContent: null,
};

const readStream = fs.createReadStream(filename, {
highWaterMark: 4096,
encoding: 'base64',
});

const chunks = [];
readStream
.on('data', chunk => {
const request = {
streamingConfig: config,
audioContent: chunk.toString(),
};
chunks.push(request);
})
.on('close', () => {
// Config-only request should be first in stream of requests
stream.write(initialRequest);
for (let i = 0; i < chunks.length; i++) {
stream.write(chunks[i]);
}
stream.end();
});

const stream = client.streamingTranslateSpeech().on('data', response => {
const {result} = response;
if (result.textTranslationResult.isFinal) {
console.log(
`\nFinal translation: ${result.textTranslationResult.translation}`
);
console.log(`Final recognition result: ${result.recognitionResult}`);
} else {
console.log(
`\nPartial translation: ${result.textTranslationResult.translation}`
);
console.log(`Partial recognition result: ${result.recognitionResult}`);
}
});

// [END mediatranslation_quickstart]
}
quickstart();
}

main(...process.argv.slice(2));
Binary file added mediatranslation/resources/audio.raw
Binary file not shown.
31 changes: 31 additions & 0 deletions mediatranslation/test/quickstart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const path = require('path');
const {assert} = require('chai');
const {describe, it} = require('mocha');
const execSync = require('child_process').execSync;
const cmd = 'node quickstart.js';

const filePath = path.join(__dirname, '..', 'resources/audio.raw');
const exec = cmd => execSync(cmd, {encoding: 'utf-8'});

describe('Quickstart', () => {
it('should translate from a streamed file', async () => {
const stdout = exec(`${cmd} ${filePath} linear16 en-US es-ES`);
assert.include(stdout, 'Partial translation');
});
});
31 changes: 31 additions & 0 deletions mediatranslation/test/translate_from_file.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const path = require('path');
const {assert} = require('chai');
const {describe, it} = require('mocha');
const execSync = require('child_process').execSync;
const cmd = 'node translate_from_file.js';

const filePath = path.join(__dirname, '..', 'resources/audio.raw');
const exec = cmd => execSync(cmd, {encoding: 'utf-8'});

describe('MediaTranslation', () => {
it('should translate from a streamed file', async () => {
const stdout = exec(`${cmd} ${filePath} linear16 en-US es-ES`);
assert.include(stdout, 'Partial translation');
});
});
Loading