@@ -32,69 +32,66 @@ import { AssemblyAI, RealtimeTranscript } from 'assemblyai'
3232import { SoxRecording } from ' ./sox.js'
3333
3434const run = async () => {
35- const client = new AssemblyAI ({
36- apiKey: ' <YOUR_API_KEY>'
37- })
35+ const client = new AssemblyAI ({
36+ apiKey: ' <YOUR_API_KEY>'
37+ })
3838
39- const SAMPLE_RATE = 16_000
39+ const SAMPLE_RATE = 16_000
4040
41- const transcriber = client .realtime .transcriber ({
42- sampleRate: SAMPLE_RATE
43- })
41+ const transcriber = client .realtime .transcriber ({
42+ sampleRate: SAMPLE_RATE
43+ })
4444
45- transcriber .on (' open' , ({ sessionId }) => {
46- console .log (` Session opened with ID: ${sessionId } ` )
47- })
45+ transcriber .on (' open' , ({ sessionId }) => {
46+ console .log (` Session opened with ID: ${sessionId } ` )
47+ })
4848
49- transcriber .on (' error' , (error : Error ) => {
50- console .error (' Error:' , error )
51- })
49+ transcriber .on (' error' , (error : Error ) => {
50+ console .error (' Error:' , error )
51+ })
5252
53- transcriber .on (' close' , (code : number , reason : string ) =>
54- console .log (' Session closed:' , code , reason )
55- )
53+ transcriber .on (' close' , (code : number , reason : string ) => {
54+ console .log (' Session closed:' , code , reason )
55+ } )
5656
57- transcriber .on (' transcript' , (transcript : RealtimeTranscript ) => {
58- if (! transcript .text ) {
59- return
60- }
57+ transcriber .on (' transcript' , (transcript : RealtimeTranscript ) => {
58+ if (! transcript .text ) {
59+ return
60+ }
6161
6262 if (transcript .message_type === ' PartialTranscript' ) {
6363 console .log (' Partial:' , transcript .text )
6464 } else {
6565 console .log (' Final:' , transcript .text )
6666 }
67+ })
6768
68- })
69-
70- console .log (' Connecting to real-time transcript service' )
71- await transcriber .connect ()
69+ console .log (' Connecting to real-time transcript service' )
70+ await transcriber .connect ()
7271
73- console .log (' Starting recording' )
74- const recording = new SoxRecording ({
75- channels: 1 ,
76- sampleRate: SAMPLE_RATE ,
77- audioType: ' wav' // Linear PCM
78- })
72+ console .log (' Starting recording' )
73+ const recording = new SoxRecording ({
74+ channels: 1 ,
75+ sampleRate: SAMPLE_RATE ,
76+ audioType: ' wav' // Linear PCM
77+ })
7978
80- recording .stream ().pipeTo (transcriber .stream ())
79+ recording .stream ().pipeTo (transcriber .stream ())
8180
82- // Stop recording and close connection using Ctrl-C.
83- process .on (' SIGINT' , async function () {
84- console .log ()
85- console .log (' Stopping recording' )
86- recording .stop ()
81+ // Stop recording and close connection using Ctrl-C.
82+ process .on (' SIGINT' , async () => {
83+ console .log ()
84+ console .log (' Stopping recording' )
85+ recording .stop ()
8786
8887 console .log (' Closing real-time transcript connection' )
8988 await transcriber .close ()
9089
9190 process .exit ()
92-
93- })
91+ })
9492}
9593
9694run ()
97-
9895````
9996< / Tab >
10097
0 commit comments