feat: heygen talking photos

This commit is contained in:
Nevo David 2025-07-21 20:56:07 +07:00
parent 38b6ad5b46
commit 5e361a7570
2 changed files with 44 additions and 14 deletions

View File

@ -85,7 +85,9 @@ const SelectVoiceComponent: FC<{
: 'bg-third'
)}
>
<div className="text-[14px] text-balance whitespace-pre-line">{p.name}</div>
<div className="text-[14px] text-balance whitespace-pre-line">
{p.name}
</div>
<div className="text-[12px]">{p.language}</div>
</div>
))}
@ -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'
);
}}
/>
<div className="text-red-400 text-[12px] mb-3">
{form?.formState?.errors?.avatar?.message || ''}

View File

@ -116,19 +116,31 @@ export class HeygenProvider extends ThirdPartyAbstract<{
aspect_ratio: string;
captions: string;
selectedVoice: string;
type: 'talking_photo' | 'avatar';
}
): Promise<string> {
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;