From b6b9857d277c56e3d155db39d01071bcc3af05f4 Mon Sep 17 00:00:00 2001 From: megatocha <127956346+megatocha@users.noreply.github.com> Date: Fri, 14 Aug 2026 15:48:59 +0200 Subject: [PATCH] fix(deepgram): use REST transcription for audio uploads Set the default content type to audio/ogg and route Transcribe directly through the REST Listen endpoint, removing the streaming fallback for file-based audio. --- Dockerfile | 12 +++++++++++- internal/deepgram/client.go | 16 ++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8fce10b..073bdce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,22 +2,32 @@ FROM golang:1.26.5-alpine AS build WORKDIR /src + COPY go.mod go.sum* ./ RUN go mod download + COPY . . + ARG VERSION=dev ARG COMMIT=none ARG DATE=unknown + RUN CGO_ENABLED=0 go build -trimpath \ -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \ -o /out/voicy ./cmd/voicy FROM alpine:3.22 + RUN apk add --no-cache ca-certificates \ && adduser -D -H -u 10001 voicy + WORKDIR /app + COPY --from=build /out/voicy /app/voicy COPY migrations /app/migrations + USER voicy + EXPOSE 8080 -ENTRYPOINT ["/app/voicy"] + +ENTRYPOINT ["/app/voicy"] \ No newline at end of file diff --git a/internal/deepgram/client.go b/internal/deepgram/client.go index 79a93e4..f4cdc2f 100644 --- a/internal/deepgram/client.go +++ b/internal/deepgram/client.go @@ -203,7 +203,7 @@ func isNormalClose(err error) bool { func (c *Client) ListenFile(ctx context.Context, audio []byte, contentType string) (Result, error) { if contentType == "" { - contentType = "application/octet-stream" + contentType = "audio/ogg" } endpoint := c.rest + ListenPath + "?" + restQuery() req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint, bytes.NewReader(audio)) @@ -227,20 +227,8 @@ func (c *Client) ListenFile(ctx context.Context, audio []byte, contentType strin return ExtractPrerecorded(body) } -// Transcribe streams first and falls back to the REST Listen endpoint. func (c *Client) Transcribe(ctx context.Context, audio []byte, contentType string, onPartial func(string)) (Result, error) { - res, err := c.StreamFile(ctx, audio, contentType, onPartial) - if err == nil && strings.TrimSpace(res.Text) != "" { - return res, nil - } - rest, restErr := c.ListenFile(ctx, audio, contentType) - if restErr != nil { - if err != nil { - return Result{}, fmt.Errorf("stream: %v; rest: %w", err, restErr) - } - return Result{}, restErr - } - return rest, nil + return c.ListenFile(ctx, audio, contentType) } func redact(key string, err error) error {