Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions ml/cloud_shell_tutorials/cloud-nl-intro/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

The Cloud Natural Language API lets you extract entities from text, perform sentiment and syntactic analysis, and classify text into categories.
The [Cloud Natural Language API](https://cloud.google.com/natural-language/) lets you extract entities from text, perform sentiment and syntactic analysis, and classify text into categories.
In this lab, we'll learn how to use the Natural Language API to analyze entities, sentiment, and syntax.

What you'll learn:
Expand Down Expand Up @@ -50,12 +50,19 @@ Next, you'll enable the Natural Language API for your project, if you've not alr

## Enable the Natural Langage API

[** TODO: what's the best approach? **]
Click on [this link](https://console.cloud.google.com/flows/enableapi?apiid=language.googleapis.com) to enable the Natural Language API for your project. (After you've enabled it, you don't need to do any further setup, as you've already set up an API key above.)

Next, you'll use the Natural Language API to analyze *entities* in text.

## Make an Entity Analysis Request

First, change to this directory in the cloud shell:

```bash
cd ~/code-snippets/ml/cloud_shell_tutorials/cloud-nl-intro
```

You'll remain in this directory for the rest of the tutorial.

The first Natural Language API method we'll use is `analyzeEntities`. With this method, the API can extract entities
(like people, places, and events) from text. To try out the API's entity analysis, we'll use the following sentence:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Next, you'll enable the Natural Language API for your project, if you've not alr

## Enable the Natural Langage API

[** TODO: what's the best approach? **]
Click on [this link](https://console.cloud.google.com/flows/enableapi?apiid=language.googleapis.com) to enable the Natural Language API for your project. (After you've enabled it, you don't need to do any further setup, as you've already set up an API key above.)

Next, you'll use the Natural Language API's `classifyText` method to classify a news article.

Expand Down
162 changes: 162 additions & 0 deletions ml/cloud_shell_tutorials/cloud-speech-intro/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Speech to Text Transcription with the Cloud Speech API

[Codelab Feedback](https://github.com/googlecodelabs/feedback/issues/new?title=[cloud-speech-intro]:&labels[]=content-platform&labels[]=cloud)


## Overview

*Duration is 1 min*


The Cloud Speech API lets you do speech to text transcription from audio files in over 80 languages.

In this lab, we will record an audio file and send it to the Cloud Speech API for transcription.

#### What you'll learn

* Creating a Speech API request and calling the API with curl
* Calling the Speech API with audio files in different languages

#### What you'll need

* A Google Cloud Platform Project
* A Browser, such [Chrome](https://www.google.com/chrome/browser/desktop/) or [Firefox](https://www.mozilla.org/firefox/)


## Create an API Key

*Duration is 2 min*


Since we'll be using curl to send a request to the Speech API, we'll need to generate an API key to pass in our request URL. To create an API key, navigate to the API Manager section of your project dashboard:

![8cbae8dc9ba56e1e.png](img/8cbae8dc9ba56e1e.png)

Then, navigate to the __Credentials__ tab and click __Create credentials__:

![fc9b83db953a127a.png](img/fc9b83db953a127a.png)

In the drop down menu, select __API key__:

![bc4940935c1bef7f.png](img/bc4940935c1bef7f.png)

Next, copy the key you just generated.

Now that you have an API key, save it to an environment variable to avoid having to insert the value of your API key in each request. You can do this in Cloud Shell. Be sure to replace `<your_api_key>` with the key you just copied.

```
export API_KEY=<YOUR_API_KEY>
```


## Create your Speech API request

*Duration is 2 min*


You can build your request to the speech API in a `request.json` file. First create this file in Cloud Shell:

```
touch request.json
```

Open it using your preferred command line editor (`nano`, `vim`, `emacs`). Add the following to your `request.json` file, replacing the `uri` value with the uri of your raw audio file:

#### __request.json__

```
{
"config": {
"encoding":"FLAC",
"sample_rate": 16000,
"language_code": "en-US"
},
"audio": {
"uri":"gs://cloud-samples-tests/speech/brooklyn.flac"
}
}
```

The request body has a `config` and `audio` object. In `config`, we tell the Speech API how to process the request. The `encoding` parameter tells the API which type of audio encoding you're using for the audio file you're sending to the API. `FLAC` is the encoding type for .raw files (see the [documentation](https://cloud.google.com/speech/reference/rest/v1/speech/recognize#audioencoding) for encoding type for more details). `sample_rate` is the rate in Hertz of the audio data you're sending to the API. There are other parameters you can add to your `config` object, but `encoding` and `sample_rate` are the only required ones.

In the `audio` object, you pass the API the uri of our audio file in Cloud Storage. Now you're ready to call the Speech API!


## Call the Speech API

*Duration is 1 min*


You can now pass your request body, along with the API key environment variable you saved earlier, to the Speech API with the following `curl` command (all in one single command line):

```
curl -s -X POST -H "Content-Type: application/json" --data-binary @request.json \
"https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=${API_KEY}"
```

Your response should look something like the following:

```
{
"results": [
{
"alternatives": [
{
"transcript": "how old is the Brooklyn Bridge",
"confidence": 0.98267895
}
]
}
]
}
```

The `transcript` value will return the Speech API's text transcription of your audio file, and the `confidence` value indicates how sure the API is that it has accurately transcribed your audio.

You'll notice that we called the `syncrecognize` method in our request above. The Speech API supports both synchronous and asynchronous speech to text transcription. In this example we sent it a complete audio file, but you can also use the `syncrecognize` method to perform streaming speech to text transcription while the user is still speaking.


## Speech to text transcription in different languages

*Duration is 2 min*


Are you multilingual? The Speech API supports speech to text transcription in over 80 languages! You can change the `language_code` parameter in `request.json`. You can find a list of supported languages [here](https://cloud.google.com/speech/docs/languages).

For example, if you had a Spanish audio file, you can set the `language_code` attributes in the `request.json` file like this:

#### __request.json__

```
{
"config": {
"encoding":"FLAC",
"sample_rate": 16000,
"language_code": "es-ES"
},
"audio": {
"uri":"gs://.../..."
}
}
```


## Congratulations!




You've learned how to perform speech to text transcription with the Speech API. In this example you passed the API the Google Cloud Storage URI of your audio file. Alternatively, you can pass a base64 encoded string of your audio content.

#### __What we've covered__

* Passing the Speech API a Google Cloud Storage URI of an audio file
* Creating a Speech API request and calling the API with curl
* Calling the Speech API with audio files in different languages

#### Next Steps

* Check out the Speech API [tutorials](https://cloud.google.com/speech/docs/tutorials) in the documentations.
* Try out the [Vision API](https://cloud.google.com/vision/) and [Natural Language API](https://cloud.google.com/natural-language/)!


133 changes: 133 additions & 0 deletions ml/cloud_shell_tutorials/cloud-translation-intro/tutorial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Translate Text with the Translation API


## Overview

The [[Cloud Translation API](https://cloud.google.com/translate/) lets you translate an arbitrary string into any supported language using state-of-the-art Neural Machine Translation.

In this lab, we'll use the Cloud Translation API from the command line to translate text and detect the language of text if the language is unknown.

![Translate API logo](https://storage.googleapis.com/aju-dev-demos-codelabs/images/Translate_API_sm.png)

**Time to complete**: About 15 minutes

Click the **Continue** button to move to the next step.

## Create an API Key

Since we'll be using curl to send a request to the Translation API, we'll need to generate an API key to pass in our request URL.

> **Note**: If you've already created an API key in this project during one of the other Cloud Shell tutorials, you can just use the existing key⸺you don't need to create another one.

To create an API key, navigate to:

**APIs & services > Credentials**:

![apis_and_services](https://storage.googleapis.com/aju-dev-demos-codelabs/images/apis_and_services.png)

Then click __Create credentials__:

![create_credentials1](https://storage.googleapis.com/aju-dev-demos-codelabs/images/create_credentials1.png)

In the drop-down menu, select __API key__:

![create_credentials2](https://storage.googleapis.com/aju-dev-demos-codelabs/images/create_credentials2.png)

Next, copy the key you just generated. Click __Close__.

Now that you have an API key, save it to an environment variable to avoid having to insert the value of your API key in each request. You can do this in Cloud Shell. Be sure to replace `<your_api_key>` with the key you just copied.

```bash
export API_KEY=<YOUR_API_KEY>
```

Next, you'll enable the Translation API for your project, if you've not already done so.

## Enable the Translation API

Click on [this link](https://console.cloud.google.com/flows/enableapi?apiid=translate.googleapis.com) to enable the Translation API for your project. (After you've enabled it, you don't need to do any further setup, as you've already set up an API key above.)

Next, you'll translate some text from English to Spanish.

## Translate Text

In this example you will translate the string "My name is Steve" into Spanish. Pass the text to be translated, along with the API key environment variable you saved earlier, to the Translation API with the following curl command:

```bash
TEXT="My%20name%20is%20Steve"
curl "https://translation.googleapis.com/language/translate/v2?target=es&key=${API_KEY}&q=${TEXT}"
```

Your response should look like the following:

```json
{
"data": {
"translations": [
{
"translatedText": "Mi nombre es Steve",
"detectedSourceLanguage": "en"
}
]
}
}
```

In the response, you can see that the translated text as well as the source language that the API detected.​


## Detect Language

In addition to translating text, the Translation API also lets you detect the language of text. In this example you will detect the language of two strings. Pass the text to be examined, along with the API key environment variable you saved earlier, to the Translation API with the following curl command:

```bash
TEXT_ONE="Meu%20nome%20é%20Steven"
TEXT_TWO="日本のグーグルのオフィスは、東京の六本木ヒルズにあります"
curl "https://translation.googleapis.com/language/translate/v2/detect?key=${API_KEY}&q=${TEXT_ONE}&q=${TEXT_TWO}"
```

Your response should look like this:

```json
{
"data": {
"detections": [
[
{
"confidence": 0.84644311666488647,
"isReliable": false,
"language": "pt"
}
],
[
{
"confidence": 1,
"isReliable": false,
"language": "ja"
}
]
]
}
}
```

The languages returned by this sample are "pt" and "ja". These are the [ISO-639-1](https://en.wikipedia.org/wiki/ISO_639-1) identifiers for Portuguese and Japanese. This [list of languages supported by the Translation API](https://cloud.google.com/translate/docs/languages) lists all the possible language codes which can be returned.


## Congratulations!

`walkthrough conclusion-trophy`

You've learned how to translate text with the Cloud Translation API!

#### What we've covered

* Creating a Cloud Translation API request and calling the API with curl
* Translating Text
* Using the Premium Edition
* Detecting Language

#### Next Steps

* Check out the [Translation API sample applications ](https://cloud.google.com/translate/docs/samples)built using client libraries using a variety of popular programming languages.
* Try out the [Vision API](https://cloud.google.com/vision/) and [Speech API](https://cloud.google.com/speech/)!
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Overview

In this lab, we'll explore the power of machine learning by using multiple machine learning APIs together. We'll start with the Cloud Vision API's text detection method to make use of Optical Character Recognition (OCR) to extract text from images. Then we'll learn how to translate that text with the Translation API and analyze it with the Natural Language API.
In this lab, we'll explore the power of machine learning by using multiple machine learning APIs together. We'll start with the [Cloud Vision API's](https://cloud.google.com/vision/) text detection method to make use of Optical Character Recognition (OCR) to extract text from images. Then we'll learn how to translate that text with the [Translation API](https://cloud.google.com/translate/) and analyze it with the [Natural Language API](https://cloud.google.com/natural-language/).

What you'll learn:

Expand Down Expand Up @@ -50,7 +50,8 @@ Next, you'll enable the Vision, Translate, and Natural Language APIs for your pr

## Enable the Vision, Translate, and Natural Language APIs

[** TODO: what's the best approach? **]
Click on [this link](https://console.cloud.google.com/flows/enableapi?apiid=vision.googleapis.com,translate.googleapis.com,language.googleapis.com) to enable the Vision, Translate, and Natural Language APIs for your project.
(After you've enabled them, you don't need to do any further setup, as you've already set up an API key above.)

Next, you'll send a request to the Cloud Vision API.

Expand Down