Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces outdated instructions that reference the Functions emulator. #1502

Merged
merged 6 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion functions/speech-to-speech/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v6.14.4
lts/dubnium
40 changes: 18 additions & 22 deletions functions/speech-to-speech/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ prerequisites:
## Configuring the sample

To configure the sample you must declare the required environment variables, set
up NVM, and install the [Cloud Functions Node.js emulator][7].
up NVM, and install the [Functions Framework][7].

The sample requires the following environment variables:

Expand All @@ -39,7 +39,7 @@ The sample requires the following environment variables:

Use the following commands to declare the required environment variables:

```
```shell
export GOOGLE_CLOUD_PROJECT=[your-GCP-project-id]
export OUTPUT_BUCKET=[your-Google-Cloud-Storage-bucket]
export GOOGLE_APPLICATION_CREDENTIALS=[path-to-your-API-key-file]
Expand All @@ -51,23 +51,24 @@ you should use to run the app.
Run the following commands to set up NVM to work with the Node.js version
declared in the `.nvmrc` file:

```
```shell
nvm install && nvm use
```

Run the following commands to install and start the Cloud Functions emulator:
Run the following commands to install and start the Functions Framework:

```
npm install -g @google-cloud/functions-emulator
functions-emulator start
```shell
cd functions
npm install
npm install --global @google-cloud/functions-framework
functions-framework --target=speechTranslate
```

## Running the tests

The test script performs the following tasks:

1. Runs the linter.
1. Deploys the function to the emulator.
1. Runs tests that don't perform any calls to the Google Cloud APIs.
1. Creates the output bucket if it doesn't exist.
1. Runs tests that perform calls to the Google Cloud APIs and drop the
Expand All @@ -77,46 +78,41 @@ The test script performs the following tasks:
To run the tests, use the following commands from the
`functions/speech-to-speech` folder:

```
```shell
npm install && npm test
```

## Sending a request to the emulator
## Sending a request to the Functions Framework

Once the tests have run, you can send a request to the emulator using an HTTP
tool, such as [curl][10]. Before sending a request, make sure that the
`OUTPUT_BUCKET` environment variable points to an existing bucket. If you update
the environment variables, you must restart the emulator to apply the new
the environment variables, you must restart the framework to apply the new
values. Use the following commands to restart the emulator:

```
functions-emulator restart
```shell
functions-framework --target=speechTranslate
```

The sample includes a `test/request-body.json` file that includes a JSON object
that represents the body of a valid request, including the base64-encoded audio
message. Run the following command to send a request to the emulator:

```
```shell
curl --request POST --header "Content-Type:application/json" \
--data @test/request-body.json $BASE_URL/speechTranslate
--data @test/request-body.json http://localhost:8080/speechTranslate
```

The command returns a JSON object with information about the translated message.
You can also see the logs using the following command:

```
functions-emulator logs read
```

[0]: https://cloud.google.com
[1]: https://cloud.google.com/speech-to-text/
[2]: https://cloud.google.com/translate/
[3]: https://cloud.google.com/text-to-speech/
[4]: https://cloud.google.com/functions/
[5]: https://cloud.google.com/storage/
[6]: https://github.com/creationix/nvm
[7]: https://cloud.google.com/functions/docs/emulator
[6]: https://github.com/nvm-sh/nvm/
[7]: https://cloud.google.com/functions/docs/functions-framework
[8]: https://cloud.google.com/docs/authentication/api-keys
[10]: https://curl.haxx.se/
[11]: https://cloud.google.com/functions/docs/locations