Transcribe Audio Files with AWS Transcribe

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "time"

    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/transcribeservice"
)

func main() {
    // Initialize a session that the SDK uses to load
    // credentials from the shared credentials file. (~/.aws/credentials).
    sess := session.Must(session.NewSessionWithOptions(session.Options{
        SharedConfigState: session.SharedConfigEnable,
    }))

    // Initiate a transcribe service
    svc := transcribeservice.New(sess)

    // Declare important info
    transcriptionJobName := "TranscriptionDemo324"
    languageCode := "en-US"
    mediaFormat := "mp3"
    mediaFileURI := "https://s3.amazonaws.com/randhunt-transcribe-demo-us-east-1/out.mp3"
    media := transcribeservice.Media{
        MediaFileUri: &mediaFileURI,
    }

    startTranscriptionJobInput := transcribeservice.StartTranscriptionJobInput{
        TranscriptionJobName: &transcriptionJobName,
        LanguageCode:         &languageCode,
        MediaFormat:          &mediaFormat,
        Media:                &media,
    }

    _, err := svc.StartTranscriptionJob(&startTranscriptionJobInput)
    if err != nil {
        fmt.Println(err)
    }

    var output transcribeservice.GetTranscriptionJobOutput
    for {
        status, err := svc.GetTranscriptionJob(&transcribeservice.GetTranscriptionJobInput{
            TranscriptionJobName: &transcriptionJobName,
        })

        if err != nil {
            fmt.Println(err)
        }

        if *status.TranscriptionJob.TranscriptionJobStatus == "COMPLETED" || *status.TranscriptionJob.TranscriptionJobStatus == "FAILED" {
            output = *status
            break
        }

        fmt.Printf("Not ready yet... %s\n", *status.TranscriptionJob.TranscriptionJobStatus)
        time.Sleep(10 * time.Second)

    }

    transcriptFileURI := *output.TranscriptionJob.Transcript.TranscriptFileUri

    out, err := os.Create(transcriptionJobName + ".json")
    if err != nil {
        fmt.Println(err)
    }
    defer out.Close()

    // Get data
    resp, err := http.Get(transcriptFileURI)
    if err != nil {
        fmt.Println(err)

    }
    defer resp.Body.Close()

    // Write body to file
    _, err = io.Copy(out, resp.Body)
    if err != nil {
        fmt.Println(err)
    }
}