47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { Body, Controller, Post, Res } from '@nestjs/common';
|
|
import { ApiBody, ApiConsumes, ApiResponse } from '@nestjs/swagger';
|
|
import { Response } from 'express';
|
|
|
|
interface Utterance {
|
|
speaker: string;
|
|
text: string;
|
|
start: number;
|
|
end: number;
|
|
confidence: number;
|
|
words: Array<{
|
|
start: number;
|
|
end: number;
|
|
text: string;
|
|
confidence: number;
|
|
speaker: string;
|
|
}>;
|
|
}
|
|
|
|
@Controller('assembly-ai')
|
|
export class AssemblyAiController {
|
|
@Post('utterance-to-script')
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'Converts utterances to a script format',
|
|
type: String,
|
|
})
|
|
@ApiBody({
|
|
description: 'Array of utterances or an object containing utterances',
|
|
type: String,
|
|
})
|
|
async utteranceToScript(
|
|
@Body() body: { utterances: Utterance[] } | Utterance[],
|
|
@Res() res: Response,
|
|
) {
|
|
const utterances = Array.isArray(body) ? body : body.utterances;
|
|
return res.header('Content-Type', 'text/plain; charset=utf-8').send(
|
|
utterances
|
|
.map(
|
|
(utterance) => `Speaker ${utterance.speaker}:
|
|
${utterance.text}`,
|
|
)
|
|
.join('\n\n'),
|
|
);
|
|
}
|
|
}
|