Skip to content

Commit 2b255a9

Browse files
author
Trevor Bye
committed
Merge branch 'user/travisw/add-golang-quickstart' of https://github.com/trrwilson/azure-docs-pr
2 parents 160d133 + 320e317 commit 2b255a9

File tree

14 files changed

+445
-45
lines changed

14 files changed

+445
-45
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
author: trrwilson
3+
ms.service: cognitive-services
4+
ms.topic: include
5+
ms.date: 03/25/2020
6+
ms.author: travisw
7+
---
8+
9+
> [!div class="nextstepaction"]
10+
> [Explore Go samples on GitHub](https://aka.ms/speech/github-go)
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
author: trrwilson
3+
ms.service: cognitive-services
4+
ms.topic: include
5+
ms.date: 05/25/2020
6+
ms.author: trrwilson
7+
---
8+
9+
## Prerequisites
10+
11+
Before you get started:
12+
13+
> [!div class="checklist"]
14+
> * [Create an Azure Speech resource](../../../../get-started.md)
15+
> * [Set up your development environment and create an empty project](../../../../quickstarts/setup-platform.md)
16+
> * Make sure that you have access to a microphone for audio capture
17+
18+
## Setup your environment
19+
20+
Update the go.mod file with the latest SDK version by adding this line
21+
```sh
22+
require (
23+
github.com/Microsoft/cognitive-services-speech-sdk-go v1.11.0-alpha1
24+
)
25+
```
26+
27+
## Start with some boilerplate code
28+
1. Replace the contents of your source file (e.g. `sr-quickstart.go`) with the below, which includes:
29+
30+
- "main" package definition
31+
- importing the necessary modules from the Speech SDK
32+
- variables for storing the subscription information that will be replaced later in this quickstart
33+
- a simple implementation using the microphone for audio input
34+
- event handlers for various events that take place during a speech recognition
35+
36+
```sh
37+
package recognizer
38+
39+
import (
40+
"bufio"
41+
"fmt"
42+
"os"
43+
44+
"github.com/Microsoft/cognitive-services-speech-sdk-go/audio"
45+
"github.com/Microsoft/cognitive-services-speech-sdk-go/speech"
46+
)
47+
48+
func recognizingHandler(event speech.SpeechRecognitionEventArgs) {
49+
defer event.Close()
50+
fmt.Println("Recognizing:", event.Result.Text)
51+
}
52+
53+
func recognizedHandler(event speech.SpeechRecognitionEventArgs) {
54+
defer event.Close()
55+
fmt.Println("Recognized:", event.Result.Text)
56+
}
57+
58+
func cancelledHandler(event speech.SpeechRecognitionCanceledEventArgs) {
59+
defer event.Close()
60+
fmt.Println("Received a cancellation: ", event.ErrorDetails)
61+
}
62+
63+
func main() {
64+
subscription := "YOUR_SUBSCRIPTION_KEY"
65+
region := "YOUR_SUBSCRIPTIONKEY_REGION"
66+
67+
audioConfig, err := audio.NewAudioConfigFromDefaultMicrophoneInput()
68+
if err != nil {
69+
fmt.Println("Got an error: ", err)
70+
return
71+
}
72+
defer audioConfig.Close()
73+
config, err := speech.NewSpeechConfigFromSubscription(subscription, region)
74+
if err != nil {
75+
fmt.Println("Got an error: ", err)
76+
return
77+
}
78+
defer config.Close()
79+
speechRecognizer, err := speech.NewSpeechRecognizerFromConfig(config, audioConfig)
80+
if err != nil {
81+
fmt.Println("Got an error: ", err)
82+
return
83+
}
84+
defer speechRecognizer.Close()
85+
speechRecognizer.Recognizing(recognizingHandler)
86+
speechRecognizer.Recognized(recognizedHandler)
87+
speechRecognizer.Canceled(cancelledHandler)
88+
speechRecognizer.StartContinuousRecognitionAsync()
89+
defer speechRecognizer.StopContinuousRecognitionAsync()
90+
bufio.NewReader(os.Stdin).ReadBytes('\n')
91+
}
92+
```
93+
94+
Replace the `YOUR_SUBSCRIPTION_KEY` and `YOUR_SUBSCRIPTIONKEY_REGION` values with actual values from the Speech resource.
95+
96+
- Navigate to the Azure portal, and open the Speech resource
97+
- Under the **Keys** on the left, there are two available subscription keys
98+
- Use either one as the `YOUR_SUBSCRIPTION_KEY` value replacement
99+
- Under the **Overview** on the left, note the region and map it to the region identifier
100+
- Use the Region identifier as the `YOUR_SUBSCRIPTIONKEY_REGION` value replacement, for example: `"westus"` for **West US**
101+
102+
## Code explanation
103+
The Speech subscription key and region are required to create a speech configuration object. The configuration object is needed to instantiate a speech recognizer object.
104+
105+
The recognizer instance exposes multiple ways to recognize speech. In this example, speech is continuously recognized. This functionality lets the Speech service know that you're sending many phrases for recognition, and when the program terminates to stop recognizing speech. As results are yielded, the code will write them to the console.
106+
107+
## Build and run
108+
You're now set up to build your project and test speech recognition using the Speech service.
109+
1. Build your project, e.g. **"go build"**
110+
2. Run the module and speak a phrase or sentence into your device's microphone. Your speech is transmitted to the Speech service and transcribed to text, which appears in the output.
111+
112+
113+
> [!NOTE]
114+
> The Speech SDK will default to recognizing using en-us for the language, see [Specify source language for speech to text](../../../../how-to-specify-source-language.md) for information on choosing the source language.
115+
116+
117+
## Next steps
118+
119+
[!INCLUDE [footer](./footer.md)]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
author: trrwilson
3+
ms.service: cognitive-services
4+
ms.topic: include
5+
ms.date: 03/25/2020
6+
ms.author: travisw
7+
---
8+
9+
If you prefer to jump right in, view or download all [Speech SDK Go Samples](https://aka.ms/speech/github-go) on GitHub. Otherwise, let's get started.

articles/cognitive-services/Speech-Service/includes/quickstarts/platform/cpp-linux.md

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ms.date: 10/14/2019
1212
ms.author: erhopf
1313
---
1414

15+
1516
This guide shows how to install the [Speech SDK](~/articles/cognitive-services/speech-service/speech-sdk.md) for Linux
1617

1718
[!INCLUDE [License Notice](~/includes/cognitive-services-speech-service-license-notice.md)]
@@ -53,42 +54,7 @@ To complete this quickstart, you'll need:
5354
> [!NOTE]
5455
> On RHEL/CentOS 8, follow the instructions on [how to configure OpenSSL for Linux](~/articles/cognitive-services/speech-service/how-to-configure-openssl-linux.md).
5556

56-
## Install Speech SDK
57-
58-
The Speech SDK for Linux can be used to build both 64-bit and 32-bit applications. The required libraries and header files can be downloaded as a tar file from https://aka.ms/csspeech/linuxbinary.
59-
60-
Download and install the SDK as follows:
61-
62-
1. Choose a directory to which the Speech SDK files should be extracted, and set the `SPEECHSDK_ROOT` environment variable to point to that directory. This variable makes it easy to refer to the directory in future commands. For example, if you want to use the directory `speechsdk` in your home directory, use a command like the following:
63-
64-
```sh
65-
export SPEECHSDK_ROOT="$HOME/speechsdk"
66-
```
67-
68-
1. Create the directory if it doesn't exist yet.
69-
70-
```sh
71-
mkdir -p "$SPEECHSDK_ROOT"
72-
```
73-
74-
1. Download and extract the `.tar.gz` archive containing the Speech SDK binaries:
75-
76-
```sh
77-
wget -O SpeechSDK-Linux.tar.gz https://aka.ms/csspeech/linuxbinary
78-
tar --strip 1 -xzf SpeechSDK-Linux.tar.gz -C "$SPEECHSDK_ROOT"
79-
```
80-
81-
1. Validate the contents of the top-level directory of the extracted package:
82-
83-
```sh
84-
ls -l "$SPEECHSDK_ROOT"
85-
```
86-
87-
The directory listing should contain the third-party notice and license files, as well as an `include` directory containing header (`.h`) files and a `lib` directory containing libraries.
88-
89-
[!INCLUDE [Linux Binary Archive Content](~/includes/cognitive-services-speech-service-linuxbinary-content.md)]
90-
91-
You can now move on to [Next steps](#next-steps) below.
57+
[!INCLUDE [linux-install-sdk](linux-install-sdk.md)]
9258

9359
## Next steps
9460

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
author: glecaros
3+
ms.service: cognitive-services
4+
ms.topic: include
5+
ms.date: 03/30/2020
6+
ms.author: gelecaro
7+
---
8+
9+
This guide shows how to install the [Speech SDK](~/articles/cognitive-services/speech-service/speech-sdk.md) for Linux
10+
11+
[!INCLUDE [License Notice](~/includes/cognitive-services-speech-service-license-notice.md)]
12+
13+
## System requirements
14+
15+
Linux (Ubuntu 16.04, Ubuntu 18.04, Debian 9, RHEL 8, CentOS 8)
16+
17+
## Prerequisites
18+
19+
To complete this quickstart, you'll need:
20+
21+
* gcc
22+
* go (1.13 or later)
23+
24+
* Supported Linux platforms will require certain libraries installed (`libssl` for secure sockets layer support and `libasound2` for sound support). Refer to your distribution below for the commands needed to install the correct versions of these libraries.
25+
26+
* On Ubuntu:
27+
28+
```sh
29+
sudo apt-get update
30+
sudo apt-get install build-essential libssl1.0.0 libasound2 wget
31+
```
32+
33+
* On Debian 9:
34+
35+
```sh
36+
sudo apt-get update
37+
sudo apt-get install build-essential libssl1.0.2 libasound2 wget
38+
```
39+
40+
* On RHEL/CentOS 8:
41+
42+
```sh
43+
sudo yum update
44+
sudo yum groupinstall "Development tools"
45+
sudo yum install alsa-lib openssl wget
46+
```
47+
48+
> [!NOTE]
49+
> On RHEL/CentOS 8, follow the instructions on [how to configure OpenSSL for Linux](~/articles/cognitive-services/speech-service/how-to-configure-openssl-linux.md).
50+
51+
[!INCLUDE [linux-install-sdk](linux-install-sdk.md)]
52+
53+
54+
## Configure Go environment
55+
56+
1. Since the bindings rely on `cgo`, you need to set the environment variables so Go can find the SDK:
57+
58+
```sh
59+
export CGO_CFLAGS="-I$SPEECHSDK_ROOT/include/c_api"
60+
export CGO_LDFLAGS="-L$SPEECHSDK_ROOT/lib -lMicrosoft.CognitiveServices.Speech.core"
61+
```
62+
63+
1. Additionally, to run applications including the SDK, we need to tell the OS
64+
where to find the libs:
65+
66+
```sh
67+
export LD_LIBRARY_PATH="$SPEECHSDK_ROOT/lib/<arch>:$LD_LIBRARY_PATH"
68+
```
69+
70+
## Next steps
71+
72+
[!INCLUDE [windows](../quickstart-list-go.md)]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
author: glecaros
3+
ms.service: cognitive-services
4+
ms.topic: include
5+
ms.date: 03/30/2020
6+
ms.author: gelecaro
7+
---
8+
9+
## Install Speech SDK
10+
11+
The Speech SDK for Linux can be used to build both 64-bit and 32-bit applications. The required libraries and header files can be downloaded as a tar file from https://aka.ms/csspeech/linuxbinary.
12+
13+
Download and install the SDK as follows:
14+
15+
1. Choose a directory to which the Speech SDK files should be extracted, and set the `SPEECHSDK_ROOT` environment variable to point to that directory. This variable makes it easy to refer to the directory in future commands. For example, if you want to use the directory `speechsdk` in your home directory, use a command like the following:
16+
17+
```sh
18+
export SPEECHSDK_ROOT="$HOME/speechsdk"
19+
```
20+
21+
1. Create the directory if it doesn't exist yet.
22+
23+
```sh
24+
mkdir -p "$SPEECHSDK_ROOT"
25+
```
26+
27+
1. Download and extract the `.tar.gz` archive containing the Speech SDK binaries:
28+
29+
```sh
30+
wget -O SpeechSDK-Linux.tar.gz https://aka.ms/csspeech/linuxbinary
31+
tar --strip 1 -xzf SpeechSDK-Linux.tar.gz -C "$SPEECHSDK_ROOT"
32+
```
33+
34+
1. Validate the contents of the top-level directory of the extracted package:
35+
36+
```sh
37+
ls -l "$SPEECHSDK_ROOT"
38+
```
39+
40+
The directory listing should contain the third-party notice and license files, as well as an `include` directory containing header (`.h`) files and a `lib` directory containing libraries.
41+
42+
[!INCLUDE [Linux Binary Archive Content](~/includes/cognitive-services-speech-service-linuxbinary-content.md)]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [Quickstart: Recognize speech from a microphone](~/articles/cognitive-services/speech-service/quickstarts/speech-to-text-from-microphone.md)
2+
- [Quickstart: Recognize speech from a file](~/articles/cognitive-services/speech-service/quickstarts/speech-to-text-from-file.md)
3+
- [Quickstart: Create a custom voice assistant](~/articles/cognitive-services/speech-service/quickstarts/voice-assistants.md)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
author: trrwilson
3+
ms.service: cognitive-services
4+
ms.topic: include
5+
ms.date: 05/25/2020
6+
ms.author: trrwilson
7+
---
8+
9+
> [!div class="nextstepaction"]
10+
> [Explore Go samples on GitHub](https://aka.ms/speech/github-go)

0 commit comments

Comments
 (0)