Skip to content

Commit 73ee22b

Browse files
authored
Merge pull request #253772 from eric-urban/patch-1
Update go.md
2 parents 43dd271 + d3f2cdb commit 73ee22b

File tree

1 file changed

+5
-118
lines changed
  • articles/ai-services/speech-service/includes/quickstarts/keyword-recognition

1 file changed

+5
-118
lines changed
Lines changed: 5 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,16 @@
1-
---
21
author: eric-urban
32
ms.service: cognitive-services
43
ms.topic: include
5-
ms.date: 02/12/2022
4+
ms.date: 10/4/2023
65
ms.author: eur
76
---
87

9-
[!INCLUDE [Header](../../common/go.md)]
10-
11-
[!INCLUDE [Introduction](intro.md)]
12-
13-
## Prerequisites
14-
158
[!INCLUDE [Prerequisites](../../common/azure-prerequisites.md)]
169

17-
> [!div class="nextstepaction"]
18-
> [I have the prerequisites](~/articles/ai-services/speech-service/get-started-speech-to-text.md?pivots=programming-language-go)
19-
> [I ran into an issue](~/articles/ai-services/speech-service/get-started-speech-to-text.md?pivots=programming-language-go)
20-
21-
## Set up the environment
22-
23-
Install the [Speech SDK for Go](../../../quickstarts/setup-platform.md?pivots=programming-language-go&tabs=dotnet%252cwindows%252cjre%252cbrowser).
24-
25-
> [!div class="nextstepaction"]
26-
> [I have the tools I need](~/articles/ai-services/speech-service/get-started-speech-to-text.md?pivots=programming-language-go)
27-
> [I ran into an issue](~/articles/ai-services/speech-service/get-started-speech-to-text.md?pivots=programming-language-go)
28-
29-
## Recognize speech from a microphone
30-
31-
Follow these steps to create a new GO module.
32-
33-
1. Open a command prompt where you want the new module, and create a new file named `speech-recognition.go`.
34-
1. Replace the contents of `speech-recognition.go` with the following code.
35-
36-
```go
37-
package main
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 sessionStartedHandler(event speech.SessionEventArgs) {
49-
defer event.Close()
50-
fmt.Println("Session Started (ID=", event.SessionID, ")")
51-
}
52-
53-
func sessionStoppedHandler(event speech.SessionEventArgs) {
54-
defer event.Close()
55-
fmt.Println("Session Stopped (ID=", event.SessionID, ")")
56-
}
57-
58-
func recognizingHandler(event speech.SpeechRecognitionEventArgs) {
59-
defer event.Close()
60-
fmt.Println("Recognizing:", event.Result.Text)
61-
}
62-
63-
func recognizedHandler(event speech.SpeechRecognitionEventArgs) {
64-
defer event.Close()
65-
fmt.Println("Recognized:", event.Result.Text)
66-
}
67-
68-
func cancelledHandler(event speech.SpeechRecognitionCanceledEventArgs) {
69-
defer event.Close()
70-
fmt.Println("Received a cancellation: ", event.ErrorDetails)
71-
}
72-
73-
func main() {
74-
subscription := "YourSubscriptionKey"
75-
region := "YourServiceRegion"
76-
77-
audioConfig, err := audio.NewAudioConfigFromDefaultMicrophoneInput()
78-
if err != nil {
79-
fmt.Println("Got an error: ", err)
80-
return
81-
}
82-
defer audioConfig.Close()
83-
speechConfig, err := speech.NewSpeechConfigFromSubscription(subscription, region)
84-
if err != nil {
85-
fmt.Println("Got an error: ", err)
86-
return
87-
}
88-
defer speechConfig.Close()
89-
speechRecognizer, err := speech.NewSpeechRecognizerFromConfig(speechConfig, audioConfig)
90-
if err != nil {
91-
fmt.Println("Got an error: ", err)
92-
return
93-
}
94-
defer speechRecognizer.Close()
95-
speechRecognizer.SessionStarted(sessionStartedHandler)
96-
speechRecognizer.SessionStopped(sessionStoppedHandler)
97-
speechRecognizer.Recognizing(recognizingHandler)
98-
speechRecognizer.Recognized(recognizedHandler)
99-
speechRecognizer.Canceled(cancelledHandler)
100-
speechRecognizer.StartContinuousRecognitionAsync()
101-
defer speechRecognizer.StopContinuousRecognitionAsync()
102-
bufio.NewReader(os.Stdin).ReadBytes('\n')
103-
}
104-
```
105-
106-
1. In `speech-recognition.go`, replace `YourSubscriptionKey` with your Speech resource key, and replace `YourServiceRegion` with your Speech resource region.
107-
108-
Run the following commands to create a `go.mod` file that links to components hosted on GitHub:
109-
110-
```cmd
111-
go mod init speech-recognition
112-
go get github.com/Microsoft/cognitive-services-speech-sdk-go
113-
```
114-
115-
Now build and run the code:
116-
117-
```cmd
118-
go build
119-
go run speech-recognition
120-
```
121-
122-
> [!div class="nextstepaction"]
123-
> [My speech was recognized](~/articles/ai-services/speech-service/get-started-speech-to-text.md?pivots=programming-language-go)
124-
> [I ran into an issue](~/articles/ai-services/speech-service/get-started-speech-to-text.md?pivots=programming-language-go)
10+
## Create a keyword in Speech Studio
12511

12+
[!INCLUDE [Create a keyword](use-speech-studio.md)]
12613

127-
## Clean up resources
14+
## Use a keyword model with the Speech SDK
12815

129-
[!INCLUDE [Delete resource](../../common/delete-resource.md)]
16+
See the [reference documentation](https://pkg.go.dev/github.com/Microsoft/cognitive-services-speech-sdk-go/speech#KeywordRecognitionModel) for using your Custom Keyword model with the Go SDK.

0 commit comments

Comments
 (0)