From 5e361a757068ed55e8f6714c9415a1c92f192bae Mon Sep 17 00:00:00 2001 From: Nevo David Date: Mon, 21 Jul 2025 20:56:07 +0700 Subject: [PATCH] feat: heygen talking photos --- .../providers/heygen.provider.tsx | 15 ++++++- .../src/3rdparties/heygen/heygen.provider.ts | 43 +++++++++++++------ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/apps/frontend/src/components/third-parties/providers/heygen.provider.tsx b/apps/frontend/src/components/third-parties/providers/heygen.provider.tsx index c092fcfa..40112b6a 100644 --- a/apps/frontend/src/components/third-parties/providers/heygen.provider.tsx +++ b/apps/frontend/src/components/third-parties/providers/heygen.provider.tsx @@ -85,7 +85,9 @@ const SelectVoiceComponent: FC<{ : 'bg-third' )} > -
{p.name}
+
+ {p.name} +
{p.language}
))} @@ -109,6 +111,7 @@ const HeygenProviderComponent = () => { aspect_ratio: '', captions: '', selectedVoice: '', + type: '', }, mode: 'all', resolver: zodResolver( @@ -205,7 +208,15 @@ const HeygenProviderComponent = () => { avatar_name: p.avatar_name || p.name, preview_image_url: p.preview_image_url || p.image_url, }))} - onChange={(id: string) => form.setValue('avatar', id)} + onChange={(id: string) => { + form.setValue('avatar', id); + form.setValue( + 'type', + data?.find((p: any) => p.id === id || p.avatar_id === id)?.id + ? 'talking_photo' + : 'avatar' + ); + }} />
{form?.formState?.errors?.avatar?.message || ''} diff --git a/libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.ts b/libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.ts index 593df310..8fc248c3 100644 --- a/libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.ts +++ b/libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.ts @@ -116,19 +116,31 @@ export class HeygenProvider extends ThirdPartyAbstract<{ aspect_ratio: string; captions: string; selectedVoice: string; + type: 'talking_photo' | 'avatar'; } ): Promise { - const {data: {video_id}} = await ( + const { + data: { video_id }, + } = await ( await fetch(`https://api.heygen.com/v2/video/generate`, { method: 'POST', body: JSON.stringify({ caption: data.captions === 'yes', video_inputs: [ { - character: { - type: 'avatar', - avatar_id: data.avatar, - }, + ...(data.type === 'avatar' + ? { + character: { + type: 'avatar', + avatar_id: data.avatar, + }, + } + : { + character: { + type: 'talking_photo', + talking_photo_id: data.avatar, + }, + }), voice: { type: 'text', input_text: data.voice, @@ -156,13 +168,20 @@ export class HeygenProvider extends ThirdPartyAbstract<{ ).json(); while (true) { - const {data: {status, video_url}} = await (await fetch(`https://api.heygen.com/v1/video_status.get?video_id=${video_id}`, { - headers: { - accept: 'application/json', - 'content-type': 'application/json', - 'x-api-key': apiKey, - }, - })).json(); + const { + data: { status, video_url }, + } = await ( + await fetch( + `https://api.heygen.com/v1/video_status.get?video_id=${video_id}`, + { + headers: { + accept: 'application/json', + 'content-type': 'application/json', + 'x-api-key': apiKey, + }, + } + ) + ).json(); if (status === 'completed') { return video_url;