aws / aws-sdk-go-v2

AWS SDK for the Go programming language.
https://aws.github.io/aws-sdk-go-v2/docs/
Apache License 2.0
2.66k stars 639 forks source link

Transcribe stream Presign #1741

Closed qhenkart closed 2 years ago

qhenkart commented 2 years ago

Describe the issue

I would like to implement a live streaming aws transcribe as well as a drag and drop file transcription. This features makes a lot more sense to be direct from the client to AWS. However to do that, I need to presign the URL which is currently not available in either the transcribe or transcribestreaming library.

Primarily I am asking for a transcribe presign url so I can presign the websocket connection stream. However, it seems to me that it would be great if the presign inner workings were exposed with an easy to use interface so we could essentially presign anything

Links

https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/transcribestreaming https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/transcribe

AWS Go SDK V2 Module Versions Used

No response

qhenkart commented 2 years ago

I found the presign SDK which resolves the upload file transcription payload. But is it possible to use this to presign a websocket connection? https://pkg.go.dev/github.com/aws/aws-sdk-go-v2@v1.16.5/aws/signer/v4

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

qhenkart commented 2 years ago

I was able to figure it out. Posting code here for anyone else

u, err := url.ParseRequestURI("wss://transcribestreaming.us-west-2.amazonaws.com:8443/stream-transcription-websocket")
    if err != nil {
        return err
    }

    req := &http.Request{
        URL:    u,
        Header: http.Header{},
        Method: "GET",
    }
    params := url.Values{
        "X-Amz-Expires":      {"100"},
        "media-encoding":     {"pcm"},
        "sample-rate":        {"48000"},
        "show-speaker-label": {"true"},
        "language-code":      {"en-US"},
    }

    req.URL.RawQuery = params.Encode()
    s := v4.NewSigner()
    signature, _, err := s.PresignHTTP(ctx, creds, req, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "transcribe", "us-west-2", time.Now())
    if err != nil {
        return err
    }

I was getting really stuck with the payload hash. I have no idea where that hash comes from since the request has no payload. However it was required. When making the socket connection AWS was returning the error saying it expected that hash at the end of the canonical string. I just pasted it here. So yours might be slightly different

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.