Go SDK
SDK Download
Setup
Download the Go SDK archive from SDK Overview, extract it, then add it to your module.
Configure the shared environment variables from Getting Started, and point KOLDAN_FILE_PATH to the audio file you want to transcribe.
Upload And Transcribe With UploadAndTranscribe
The example below keeps the request intentionally minimal: upload one file, start transcription with the general model alias, poll until the job finishes, and print either the transcript or the error details.
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"time"
koldan "koldan-sdk"
)
func main() {
cfg := koldan.NewConfiguration()
cfg.Servers[0].URL = os.Getenv("KOLDAN_BASE_URL")
client := koldan.NewAPIClient(cfg)
ctx := context.WithValue(context.Background(), koldan.ContextAPIKeys, map[string]koldan.APIKey{
"apiKey": {Key: os.Getenv("KOLDAN_API_KEY")},
})
f, err := os.Open(os.Getenv("KOLDAN_FILE_PATH"))
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
defer f.Close()
transcription := `{"model":"general","punctuation":false,"capitalization":false}`
diarization := `{"enabled":false}`
resp, _, err := client.SpeechTranscriptionsAPI.UploadAndTranscribe(ctx).
Name("meeting-recording").
Transcription(transcription).
Diarization(diarization).
File(f).
Execute()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
job := resp.GetJob()
for {
jobResp, _, err := client.SpeechTranscriptionsAPI.GetJob(ctx, job.GetId()).Execute()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
job = *jobResp
fmt.Println("Job status:", job.GetStatus())
if job.GetStatus() == koldan.COMPLETED || job.GetStatus() == koldan.FAILED || job.GetStatus() == koldan.CANCELLED {
break
}
time.Sleep(2 * time.Second)
}
if job.GetStatus() == koldan.COMPLETED {
result := job.GetResult()
fmt.Println(result.GetText())
} else {
errs, _ := json.Marshal(job.GetErrors())
fmt.Println(string(errs))
}
}
Run
Expected Result
A successful run prints Job status: ... updates and then the transcription text from your uploaded audio.
If the job fails, the example prints the error array returned by the API.