|
1 |
| ---- |
2 | 1 | author: eric-urban
|
3 | 2 | ms.service: cognitive-services
|
4 | 3 | ms.topic: include
|
5 |
| -ms.date: 02/12/2022 |
| 4 | +ms.date: 10/4/2023 |
6 | 5 | ms.author: eur
|
7 | 6 | ---
|
8 | 7 |
|
9 |
| -[!INCLUDE [Header](../../common/go.md)] |
10 |
| - |
11 |
| -[!INCLUDE [Introduction](intro.md)] |
12 |
| - |
13 |
| -## Prerequisites |
14 |
| - |
15 | 8 | [!INCLUDE [Prerequisites](../../common/azure-prerequisites.md)]
|
16 | 9 |
|
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 |
125 | 11 |
|
| 12 | +[!INCLUDE [Create a keyword](use-speech-studio.md)] |
126 | 13 |
|
127 |
| -## Clean up resources |
| 14 | +## Use a keyword model with the Speech SDK |
128 | 15 |
|
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