|
|
@@ -1,7 +1,7 @@ |
|
|
|
import { |
|
|
|
createSummarizer, |
|
|
|
CreateSummarizerParams, |
|
|
|
VideoType, |
|
|
|
CreateSummarizerParams, SummarizerEventEmitter, |
|
|
|
SummarizerProcessParams, |
|
|
|
} from '@modal-sh/webvideo-transcript-summary-core'; |
|
|
|
|
|
|
|
export interface SummaryResult { |
|
|
@@ -11,21 +11,32 @@ export interface SummaryResult { |
|
|
|
} |
|
|
|
|
|
|
|
export interface SummaryService { |
|
|
|
summarizeVideoTranscript(params: CreateSummarizerParams): Promise<Partial<SummaryResult>> |
|
|
|
initializeSummarizer(params: CreateSummarizerParams): void; |
|
|
|
summarizeVideoTranscript(processParams: SummarizerProcessParams): Promise<Partial<SummaryResult>>; |
|
|
|
} |
|
|
|
|
|
|
|
export class SummaryServiceImpl implements SummaryService { |
|
|
|
private summarizer?: SummarizerEventEmitter; |
|
|
|
|
|
|
|
constructor(private readonly logger = console) { |
|
|
|
// noop |
|
|
|
} |
|
|
|
|
|
|
|
summarizeVideoTranscript(params: CreateSummarizerParams) { |
|
|
|
initializeSummarizer(params: CreateSummarizerParams): void { |
|
|
|
this.summarizer = createSummarizer(params); |
|
|
|
} |
|
|
|
|
|
|
|
summarizeVideoTranscript(processParams: SummarizerProcessParams) { |
|
|
|
return new Promise<Partial<SummaryResult>>((resolve, reject) => { |
|
|
|
if (!this.summarizer) { |
|
|
|
reject(new Error('Summarizer is not initialized')); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const successEvent = {} as Partial<SummaryResult>; |
|
|
|
let error: Error; |
|
|
|
const summarizer = createSummarizer(params); |
|
|
|
|
|
|
|
summarizer.on('process', (data) => { |
|
|
|
this.summarizer.on('process', (data) => { |
|
|
|
this.logger.log('process', data); |
|
|
|
if (data.phase === 'success') { |
|
|
|
switch (data.processType) { |
|
|
@@ -47,12 +58,12 @@ export class SummaryServiceImpl implements SummaryService { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
summarizer.on('error', (err) => { |
|
|
|
this.summarizer.on('error', (err) => { |
|
|
|
this.logger.log('error', err); |
|
|
|
error = err; |
|
|
|
}); |
|
|
|
|
|
|
|
summarizer.on('end', () => { |
|
|
|
this.summarizer.on('end', () => { |
|
|
|
this.logger.log('end'); |
|
|
|
if (error) { |
|
|
|
reject(error); |
|
|
@@ -61,7 +72,7 @@ export class SummaryServiceImpl implements SummaryService { |
|
|
|
resolve(successEvent); |
|
|
|
}); |
|
|
|
|
|
|
|
summarizer.process(); |
|
|
|
this.summarizer.process(processParams); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |