|
1 | | -import { createReadStream } from "fs"; |
2 | | -import { join } from "path"; |
| 1 | +import { TranscribeStreaming } from "@aws-sdk/client-transcribe-streaming"; |
| 2 | +import { createReadStream } from "node:fs"; |
| 3 | +import { join } from "node:path"; |
3 | 4 | import { afterAll, beforeAll, describe, expect, test as it } from "vitest"; |
4 | 5 |
|
5 | | -import { TranscribeStreaming } from "../src/index"; |
6 | 6 | const audio = createReadStream(join(__dirname, "numbers.wav")); |
7 | 7 |
|
8 | | -describe("TranscribeStream client", () => { |
9 | | - const client = new TranscribeStreaming({ |
10 | | - region: "us-west-2", |
11 | | - credentials: { |
12 | | - accessKeyId: "CLIENT_TEST", |
13 | | - secretAccessKey: "CLIENT_TEST", |
14 | | - }, |
15 | | - }); |
16 | | - |
17 | | - beforeAll(async () => {}); |
18 | | - afterAll(() => { |
19 | | - client.destroy(); |
20 | | - }); |
| 8 | +describe( |
| 9 | + "TranscribeStream client", |
| 10 | + () => { |
| 11 | + const client = new TranscribeStreaming({ |
| 12 | + region: "us-west-2", |
| 13 | + }); |
21 | 14 |
|
22 | | - // TODO: not working in Node.js with HTTP2 handler? |
23 | | - it.skip("should stream the transcript", async () => { |
24 | | - const LanguageCode = "en-GB"; |
25 | | - const MediaEncoding = "pcm"; |
26 | | - const MediaSampleRateHertz = 44100; |
27 | | - const result = await client.startStreamTranscription({ |
28 | | - LanguageCode, |
29 | | - MediaEncoding, |
30 | | - MediaSampleRateHertz, |
31 | | - AudioStream: (async function* () { |
32 | | - for await (const chunk of audio) { |
33 | | - yield { AudioEvent: { AudioChunk: chunk } }; |
34 | | - } |
35 | | - })(), |
| 15 | + beforeAll(async () => {}); |
| 16 | + afterAll(() => { |
| 17 | + client.destroy(); |
36 | 18 | }); |
37 | | - expect(result.LanguageCode).toBe(LanguageCode); |
38 | | - expect(result.MediaEncoding).toBe(MediaEncoding); |
39 | | - expect(result.MediaSampleRateHertz).toBe(MediaSampleRateHertz); |
40 | | - expect(result.TranscriptResultStream).toBeDefined(); |
41 | | - const transcripts: any[] = []; |
42 | | - for await (const event of result.TranscriptResultStream!) { |
43 | | - transcripts.push(event); |
44 | | - } |
45 | | - expect(transcripts.filter((event) => event["TranscriptEvent"]).length).toBeGreaterThan(0); |
46 | | - }, 60000); |
47 | | -}); |
| 19 | + |
| 20 | + it("should stream the transcript", async () => { |
| 21 | + const LanguageCode = "en-GB"; |
| 22 | + const MediaEncoding = "pcm"; |
| 23 | + const MediaSampleRateHertz = 44100; |
| 24 | + const result = await client.startStreamTranscription({ |
| 25 | + LanguageCode, |
| 26 | + MediaEncoding, |
| 27 | + MediaSampleRateHertz, |
| 28 | + AudioStream: (async function* () { |
| 29 | + for await (const chunk of audio) { |
| 30 | + yield { AudioEvent: { AudioChunk: chunk } }; |
| 31 | + } |
| 32 | + })(), |
| 33 | + }); |
| 34 | + expect(result.LanguageCode).toBe(LanguageCode); |
| 35 | + expect(result.MediaEncoding).toBe(MediaEncoding); |
| 36 | + expect(result.MediaSampleRateHertz).toBe(MediaSampleRateHertz); |
| 37 | + expect(result.TranscriptResultStream).toBeDefined(); |
| 38 | + const transcripts: any[] = []; |
| 39 | + for await (const event of result.TranscriptResultStream!) { |
| 40 | + transcripts.push(event); |
| 41 | + } |
| 42 | + expect(transcripts.filter((event) => event["TranscriptEvent"]).length).toBeGreaterThan(0); |
| 43 | + }, 60000); |
| 44 | + }, |
| 45 | + { |
| 46 | + retry: 4, |
| 47 | + } |
| 48 | +); |
0 commit comments