@@ -17,15 +17,17 @@ A Go client library for accessing [AssemblyAI](https://assemblyai.com).
17
17
## Overview
18
18
19
19
- [ AssemblyAI Go SDK] ( #assemblyai-go-sdk )
20
- - [ Overview] ( #overview )
21
- - [ Documentation] ( #documentation )
22
- - [ Quickstart] ( #quickstart )
23
- - [ Installation] ( #installation )
24
- - [ Examples] ( #examples )
25
- - [ Core Transcription] ( #core-transcription )
26
- - [ Audio Intelligence] ( #audio-intelligence )
27
- - [ Real-Time Transcription] ( #real-time-transcription )
28
- - [ Playgrounds] ( #playgrounds )
20
+ - [ Overview] ( #overview )
21
+ - [ Documentation] ( #documentation )
22
+ - [ Quickstart] ( #quickstart )
23
+ - [ Installation] ( #installation )
24
+ - [ Examples] ( #examples )
25
+ - [ Core Transcription] ( #core-transcription )
26
+ - [ Audio Intelligence] ( #audio-intelligence )
27
+ - [ Real-Time Transcription] ( #real-time-transcription )
28
+ - [ Playgrounds] ( #playgrounds )
29
+ - [ Tips and tricks] ( #tips-and-tricks )
30
+ - [ Inspect API errors] ( #inspect-api-errors )
29
31
30
32
## Documentation
31
33
@@ -54,28 +56,28 @@ Before you begin, you need to have your API key. If you don't have one yet, [**s
54
56
package main
55
57
56
58
import (
57
- " context"
58
- " log"
59
- " os"
59
+ " context"
60
+ " log"
61
+ " os"
60
62
61
- " github.com/AssemblyAI/assemblyai-go-sdk"
63
+ " github.com/AssemblyAI/assemblyai-go-sdk"
62
64
)
63
65
64
66
func main () {
65
- apiKey := os.Getenv (" ASSEMBLYAI_API_KEY" )
67
+ apiKey := os.Getenv (" ASSEMBLYAI_API_KEY" )
66
68
67
- ctx := context.Background ()
69
+ ctx := context.Background ()
68
70
69
- audioURL := " https://example.org/audio.mp3"
71
+ audioURL := " https://example.org/audio.mp3"
70
72
71
- client := assemblyai.NewClient (apiKey)
73
+ client := assemblyai.NewClient (apiKey)
72
74
73
- transcript , err := client.Transcripts .TranscribeFromURL (ctx, audioURL, nil )
74
- if err != nil {
75
- log.Fatal (" Something bad happened:" , err)
76
- }
75
+ transcript , err := client.Transcripts .TranscribeFromURL (ctx, audioURL, nil )
76
+ if err != nil {
77
+ log.Fatal (" Something bad happened:" , err)
78
+ }
77
79
78
- log.Println (*transcript.Text )
80
+ log.Println (*transcript.Text )
79
81
}
80
82
```
81
83
@@ -87,32 +89,32 @@ func main() {
87
89
package main
88
90
89
91
import (
90
- " context"
91
- " log"
92
- " os"
92
+ " context"
93
+ " log"
94
+ " os"
93
95
94
- " github.com/AssemblyAI/assemblyai-go-sdk"
96
+ " github.com/AssemblyAI/assemblyai-go-sdk"
95
97
)
96
98
97
99
func main () {
98
- apiKey := os.Getenv (" ASSEMBLYAI_API_KEY" )
100
+ apiKey := os.Getenv (" ASSEMBLYAI_API_KEY" )
99
101
100
- ctx := context.Background ()
102
+ ctx := context.Background ()
101
103
102
- client := assemblyai.NewClient (apiKey)
104
+ client := assemblyai.NewClient (apiKey)
103
105
104
- f , err := os.Open (" ./my-local-audio-file.wav" )
105
- if err != nil {
106
- log.Fatal (" Couldn't open audio file:" , err)
107
- }
108
- defer f.Close ()
106
+ f , err := os.Open (" ./my-local-audio-file.wav" )
107
+ if err != nil {
108
+ log.Fatal (" Couldn't open audio file:" , err)
109
+ }
110
+ defer f.Close ()
109
111
110
- transcript , err := client.Transcripts .TranscribeFromReader (ctx, f, nil )
111
- if err != nil {
112
- log.Fatal (" Something bad happened:" , err)
113
- }
112
+ transcript , err := client.Transcripts .TranscribeFromReader (ctx, f, nil )
113
+ if err != nil {
114
+ log.Fatal (" Something bad happened:" , err)
115
+ }
114
116
115
- log.Println (*transcript.Text )
117
+ log.Println (*transcript.Text )
116
118
}
117
119
```
118
120
@@ -127,36 +129,36 @@ func main() {
127
129
package main
128
130
129
131
import (
130
- " context"
131
- " log"
132
- " os"
132
+ " context"
133
+ " log"
134
+ " os"
133
135
134
- " github.com/AssemblyAI/assemblyai-go-sdk"
136
+ " github.com/AssemblyAI/assemblyai-go-sdk"
135
137
)
136
138
137
139
func main () {
138
- apiKey := os.Getenv (" ASSEMBLYAI_API_KEY" )
140
+ apiKey := os.Getenv (" ASSEMBLYAI_API_KEY" )
139
141
140
- ctx := context.Background ()
142
+ ctx := context.Background ()
141
143
142
- audioURL := " https://example.org/audio.mp3"
144
+ audioURL := " https://example.org/audio.mp3"
143
145
144
- client := assemblyai.NewClient (apiKey)
146
+ client := assemblyai.NewClient (apiKey)
145
147
146
- opts := &assemblyai.TranscriptParams {
147
- EntityDetection: assemblyai.Bool (true ),
148
- }
148
+ opts := &assemblyai.TranscriptParams {
149
+ EntityDetection: assemblyai.Bool (true ),
150
+ }
149
151
150
- transcript , err := client.Transcripts .TranscribeFromURL (ctx, audioURL, opts)
151
- if err != nil {
152
- log.Fatal (" Something bad happened:" , err)
153
- }
152
+ transcript , err := client.Transcripts .TranscribeFromURL (ctx, audioURL, opts)
153
+ if err != nil {
154
+ log.Fatal (" Something bad happened:" , err)
155
+ }
154
156
155
- for _ , entity := range transcript.Entities {
156
- log.Println (*entity.Text )
157
- log.Println (entity.EntityType )
158
- log.Printf (" Timestamp: %v - %v " , *entity.Start , *entity.End )
159
- }
157
+ for _ , entity := range transcript.Entities {
158
+ log.Println (*entity.Text )
159
+ log.Println (entity.EntityType )
160
+ log.Printf (" Timestamp: %v - %v " , *entity.Start , *entity.End )
161
+ }
160
162
}
161
163
```
162
164
@@ -172,3 +174,22 @@ Visit one of our Playgrounds:
172
174
173
175
- [ LeMUR Playground] ( https://www.assemblyai.com/playground/v2/source )
174
176
- [ Transcription Playground] ( https://www.assemblyai.com/playground )
177
+
178
+ ## Tips and tricks
179
+
180
+ ### Inspect API errors
181
+
182
+ If you receive an API error, you can inspect the HTTP response returned by the API for more details:
183
+
184
+ ``` go
185
+ transcript , err := client.Transcripts .TranscribeFromURL (ctx, audioURL, nil )
186
+ if err != nil {
187
+ var apierr aai.APIError
188
+ if errors.As (err, &apierr) {
189
+ // apierr.Response is the *http.Response from the API call.
190
+ fmt.Println (apierr.Response .StatusCode )
191
+ } else {
192
+ // err is not an API error.
193
+ }
194
+ }
195
+ ```
0 commit comments