1- // TODO WES BOS Remove
2- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3- // @ts -nocheck
4- import DeepgramPkg from '@deepgram/sdk' ;
5- const { Deepgram } = DeepgramPkg ;
1+ import { createClient } from '@deepgram/sdk' ;
62import { prisma_client as prisma } from '$/server/prisma-client' ;
73import { error } from '@sveltejs/kit' ;
84import { keywords } from './fixes' ;
95import { addFlaggerAudio } from './flagger' ;
106import { save_transcript_to_db } from './transcripts' ;
11- import type { PrerecordedTranscriptionResponse } from '@deepgram/sdk/dist/types' ;
12- const deepgramApiKey = process . env . DEEPGRAM_SECRET ;
13- if ( ! deepgramApiKey ) {
7+
8+ const deepgram_api_key = process . env . DEEPGRAM_SECRET ;
9+ if ( ! deepgram_api_key ) {
1410 console . error ( 'Please set the DEEPGRAM_SECRET environment variable.' ) ;
1511 process . exit ( 1 ) ;
1612}
1713
18- // Initializes the Deepgram SDK
19- export const deepgramClient = new Deepgram ( deepgramApiKey , 'api.deepgram.com' ) ;
14+ export const deepgram_client = createClient ( deepgram_api_key ) ;
2015
2116export async function get_transcript ( showNumber : number ) {
2217 const show = await prisma . show . findUnique ( {
@@ -35,39 +30,29 @@ export async function get_transcript(showNumber: number) {
3530 `Transcript for show #${ show . number } already exists. Delete it if you want to re-fetch it.`
3631 ) ;
3732 }
38- const showBuffer = await addFlaggerAudio ( show ) ;
33+ const show_buffer = await addFlaggerAudio ( show ) ;
3934 console . log ( `Fetching transcript for show #${ show . number } - ${ show . title } ...` ) ;
40- console . log ( showBuffer ) ;
41- // const filePath = join(process.cwd(), 'temp-transcript.json');
42- const transcript : PrerecordedTranscriptionResponse = await deepgramClient . transcription
43- . preRecorded (
44- {
45- buffer : showBuffer ,
46- mimetype : 'audio/mpeg'
47- } ,
48- {
49- punctuate : true ,
50- model : 'nova-2-ea' ,
51- language : 'en-US' ,
52- detect_entities : true ,
53- diarize : true ,
54- smart_format : true ,
55- paragraphs : true , // Not very good
56- utterances : true ,
57- detect_topics : false , // not very good
58- keywords
59- }
60- )
61- . catch ( ( e ) => {
62- console . log ( `Error fetching transcript for show #${ show . number } - ${ show . title } .` ) ;
63- console . log ( e ) ;
35+
36+ try {
37+ const transcript = await deepgram_client . listen . prerecorded . transcribeFile ( show_buffer , {
38+ punctuate : true ,
39+ model : 'nova-2-ea' ,
40+ language : 'en-US' ,
41+ detect_entities : true ,
42+ diarize : true ,
43+ smart_format : true ,
44+ paragraphs : true , // Not very good
45+ utterances : true ,
46+ detect_topics : false , // not very good
47+ keywords
6448 } ) ;
65- // Temp: Write to disk as temp-transcript.json
66- // const transcript = JSON.parse(await readFile(filePath, 'utf-8'));
67- // await writeFile(filePath, JSON.stringify(transcript, null, 2));
68- console . log ( `Transcript for show #${ show . number } - ${ show . title } fetched.` ) ;
69- await save_transcript_to_db ( show , transcript . results ?. utterances || [ ] ) ;
7049
71- // await writeFile(filePath, JSON.stringify(transcript, null, 2));
72- console . log ( `Transcript for show #${ show . number } - ${ show . title } saved.` ) ;
50+ console . log ( `Transcript for show #${ show . number } - ${ show . title } fetched.` ) ;
51+ await save_transcript_to_db ( show , transcript . result ?. results . utterances || [ ] ) ;
52+
53+ console . log ( `Transcript for show #${ show . number } - ${ show . title } saved.` ) ;
54+ } catch ( e ) {
55+ console . log ( `Error fetching transcript for show #${ show . number } - ${ show . title } .` ) ;
56+ console . log ( e ) ;
57+ }
7358}
0 commit comments