Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions assemblyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"os"
)

const (
version = "1.5.0"
version = "1.5.1"
defaultBaseURLScheme = "https"
defaultBaseURLHost = "api.assemblyai.com"
defaultUserAgent = "assemblyai-go/" + version
)

// Client manages the communication with the AssemblyAI API.
Expand All @@ -41,7 +41,7 @@ func NewClientWithOptions(opts ...ClientOption) *Client {
Scheme: defaultBaseURLScheme,
Host: defaultBaseURLHost,
},
userAgent: defaultUserAgent,
userAgent: fmt.Sprintf("AssemblyAI/1.0 (sdk=Go/%s)", version),
httpClient: &http.Client{},
apiKey: defaultAPIKey,
}
Expand Down Expand Up @@ -157,7 +157,12 @@ func (c *Client) do(req *http.Request, v interface{}) (*http.Response, error) {
}

if v != nil {
err = json.NewDecoder(resp.Body).Decode(v)
switch val := v.(type) {
case *[]byte:
*val, err = io.ReadAll(resp.Body)
default:
err = json.NewDecoder(resp.Body).Decode(v)
}
}

return resp, err
Expand Down
4 changes: 1 addition & 3 deletions examples/realtime/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package main
import (
"context"
"fmt"
"log/slog"
"os"
"os/signal"
"syscall"

"log/slog"

"github.com/AssemblyAI/assemblyai-go-sdk"
"github.com/gordonklaus/portaudio"
)
Expand Down Expand Up @@ -36,7 +35,6 @@ func (h *realtimeHandler) Error(err error) {
}

func main() {

sigs := make(chan os.Signal, 1)

signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
Expand Down
199 changes: 199 additions & 0 deletions testdata/transcript/subtitles.srt
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
1
00:00:05,400 --> 00:00:12,550
Runner's knee runner's

2
00:00:12,582 --> 00:00:16,086
knee is a condition characterized by pain behind or around

3
00:00:16,150 --> 00:00:19,422
the kneecap. It is caused by overuse,

4
00:00:19,518 --> 00:00:23,870
muscle imbalance and inadequate stretching. Symptoms include

5
00:00:23,982 --> 00:00:27,294
pain under or around the kneecap, pain when

6
00:00:27,334 --> 00:00:30,782
walking sprained ankle one

7
00:00:30,798 --> 00:00:33,470
nil here in the 37th minute she is between two guatemalan

8
00:00:33,502 --> 00:00:36,782
defenders and then goes down and stays down and

9
00:00:36,798 --> 00:00:40,134
you will see why. The ligaments of the ankle holds the ankle

10
00:00:40,174 --> 00:00:43,798
bones and joint in position. They protect the ankle

11
00:00:43,846 --> 00:00:46,870
from abnormal movements such as twisting, turning and

12
00:00:46,902 --> 00:00:50,710
rolling of the foot. A sprained ankle happens when the

13
00:00:50,742 --> 00:00:54,434
foot twists, rolls or turns beyond its normal motions.

14
00:00:55,484 --> 00:00:58,864
If the force is too strong, the ligaments can tear.

15
00:00:59,404 --> 00:01:02,844
Symptoms include pain and difficulty moving the ankle,

16
00:01:03,004 --> 00:01:05,784
swelling around the ankle and bruising.

17
00:01:08,004 --> 00:01:11,252
Meniscus tear I think some of it was just

18
00:01:11,308 --> 00:01:14,804
being scared, but this guy doesn't like you. Want to go

19
00:01:14,844 --> 00:01:18,756
after Patrick each of your knees has two menisci c shaped

20
00:01:18,780 --> 00:01:21,792
pieces of cartilage that act like a cushion between your

21
00:01:21,808 --> 00:01:23,604
shin bone and your thigh bone.

22
00:01:25,504 --> 00:01:28,888
A meniscus tear happens when you forcibly twist or rotate

23
00:01:28,936 --> 00:01:31,952
your knee, especially when putting the pressure of your full

24
00:01:32,008 --> 00:01:36,144
weight on it, leading to a torn meniscus. Symptoms include

25
00:01:36,264 --> 00:01:39,288
stiffness and swelling, pain in your knee,

26
00:01:39,456 --> 00:01:43,368
catching or locking of your knee rotator

27
00:01:43,416 --> 00:01:46,996
cuff tear has a torn rotator cuff cuff go be traveling

28
00:01:47,020 --> 00:01:50,676
to Los Angeles today to be examined by teen doctors on the

29
00:01:50,700 --> 00:01:54,156
rotator cuff attaches the humerus to the shoulder blade and

30
00:01:54,180 --> 00:01:56,344
helps to lift and rotate your arm.

31
00:01:58,084 --> 00:02:01,940
A rotator cuff tear is caused by a fall onto your arm or

32
00:02:01,972 --> 00:02:04,304
if you lift a heavy object too fast,

33
00:02:06,284 --> 00:02:09,420
the tendon can partially or completely tear off of the

34
00:02:09,452 --> 00:02:13,160
humerus. Head symptoms

35
00:02:13,192 --> 00:02:16,364
include pain when lifting and lowering your arm,

36
00:02:16,664 --> 00:02:19,364
weakness when lifting or rotating your arm,

37
00:02:19,664 --> 00:02:22,284
pain when lying on the affected shoulder.

38
00:02:25,544 --> 00:02:29,504
ACL tear here's Rosario on the brake now and watch.

39
00:02:29,664 --> 00:02:32,888
Nerls go up with the left hand, block the shot, and then on

40
00:02:32,936 --> 00:02:36,376
landing, there came the the ACL runs diagonally in the

41
00:02:36,400 --> 00:02:38,484
middle of the knee and provides stability.

42
00:02:40,034 --> 00:02:43,330
Anterior cruciate ligament tear occurs when your foot

43
00:02:43,362 --> 00:02:46,714
is firmly planted on the ground and a sudden force hits your

44
00:02:46,754 --> 00:02:49,574
knee while your leg is straight or slightly bent.

45
00:02:52,194 --> 00:02:55,282
This can happen when you are changing direction rapidly,

46
00:02:55,418 --> 00:02:58,294
slowing down when running or landing from a jump.

47
00:02:59,834 --> 00:03:02,690
The ligament completely tears into two pieces,

48
00:03:02,842 --> 00:03:04,574
making the knee unstable.

49
00:03:06,274 --> 00:03:09,826
Symptoms include severe pain and tenderness in knee,

50
00:03:10,010 --> 00:03:13,514
loss of full range of motion, swelling around the knee.
6 changes: 4 additions & 2 deletions transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ func (s *TranscriptService) GetSubtitles(ctx context.Context, transcriptID strin
req.URL.RawQuery = values.Encode()
}

resp, err := s.client.do(req, nil)
var res []byte

resp, err := s.client.do(req, &res)
if err != nil {
return nil, err
}
defer resp.Body.Close()

return io.ReadAll(resp.Body)
return res, nil
}

// List returns a collection of transcripts based on a filter.
Expand Down
38 changes: 38 additions & 0 deletions transcript_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package assemblyai

import (
"bufio"
"bytes"
"context"
"encoding/json"
Expand Down Expand Up @@ -238,6 +239,43 @@ func TestTranscripts_SearchWords(t *testing.T) {
require.Equal(t, want, results)
}

func TestTranscripts_GetSubtitles(t *testing.T) {
t.Parallel()

client, handler, teardown := setup()
defer teardown()

handler.HandleFunc("/v2/transcript/"+fakeTranscriptID+"/srt", func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "GET", r.Method)
require.Equal(t, "chars_per_caption=60", r.URL.RawQuery)

writeFileResponse(t, w, "testdata/transcript/subtitles.srt")
})

ctx := context.Background()

st, err := client.Transcripts.GetSubtitles(ctx, fakeTranscriptID, "srt", &TranscriptGetSubtitlesOptions{
CharsPerCaption: 60,
})
require.NoError(t, err)

r := bufio.NewReader(bytes.NewReader(st))

var line []byte

line, _, err = r.ReadLine()
require.NoError(t, err)
require.Equal(t, []byte("1"), line)

line, _, err = r.ReadLine()
require.NoError(t, err)
require.Equal(t, []byte("00:00:05,400 --> 00:00:12,550"), line)

line, _, err = r.ReadLine()
require.NoError(t, err)
require.Equal(t, []byte("Runner's knee runner's"), line)
}

func TestAPIError(t *testing.T) {
t.Parallel()

Expand Down
Loading