Skip to content

Commit 5e361a7

Browse files
committed
feat: heygen talking photos
1 parent 38b6ad5 commit 5e361a7

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

apps/frontend/src/components/third-parties/providers/heygen.provider.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ const SelectVoiceComponent: FC<{
8585
: 'bg-third'
8686
)}
8787
>
88-
<div className="text-[14px] text-balance whitespace-pre-line">{p.name}</div>
88+
<div className="text-[14px] text-balance whitespace-pre-line">
89+
{p.name}
90+
</div>
8991
<div className="text-[12px]">{p.language}</div>
9092
</div>
9193
))}
@@ -109,6 +111,7 @@ const HeygenProviderComponent = () => {
109111
aspect_ratio: '',
110112
captions: '',
111113
selectedVoice: '',
114+
type: '',
112115
},
113116
mode: 'all',
114117
resolver: zodResolver(
@@ -205,7 +208,15 @@ const HeygenProviderComponent = () => {
205208
avatar_name: p.avatar_name || p.name,
206209
preview_image_url: p.preview_image_url || p.image_url,
207210
}))}
208-
onChange={(id: string) => form.setValue('avatar', id)}
211+
onChange={(id: string) => {
212+
form.setValue('avatar', id);
213+
form.setValue(
214+
'type',
215+
data?.find((p: any) => p.id === id || p.avatar_id === id)?.id
216+
? 'talking_photo'
217+
: 'avatar'
218+
);
219+
}}
209220
/>
210221
<div className="text-red-400 text-[12px] mb-3">
211222
{form?.formState?.errors?.avatar?.message || ''}

libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,31 @@ export class HeygenProvider extends ThirdPartyAbstract<{
116116
aspect_ratio: string;
117117
captions: string;
118118
selectedVoice: string;
119+
type: 'talking_photo' | 'avatar';
119120
}
120121
): Promise<string> {
121-
const {data: {video_id}} = await (
122+
const {
123+
data: { video_id },
124+
} = await (
122125
await fetch(`https://api.heygen.com/v2/video/generate`, {
123126
method: 'POST',
124127
body: JSON.stringify({
125128
caption: data.captions === 'yes',
126129
video_inputs: [
127130
{
128-
character: {
129-
type: 'avatar',
130-
avatar_id: data.avatar,
131-
},
131+
...(data.type === 'avatar'
132+
? {
133+
character: {
134+
type: 'avatar',
135+
avatar_id: data.avatar,
136+
},
137+
}
138+
: {
139+
character: {
140+
type: 'talking_photo',
141+
talking_photo_id: data.avatar,
142+
},
143+
}),
132144
voice: {
133145
type: 'text',
134146
input_text: data.voice,
@@ -156,13 +168,20 @@ export class HeygenProvider extends ThirdPartyAbstract<{
156168
).json();
157169

158170
while (true) {
159-
const {data: {status, video_url}} = await (await fetch(`https://api.heygen.com/v1/video_status.get?video_id=${video_id}`, {
160-
headers: {
161-
accept: 'application/json',
162-
'content-type': 'application/json',
163-
'x-api-key': apiKey,
164-
},
165-
})).json();
171+
const {
172+
data: { status, video_url },
173+
} = await (
174+
await fetch(
175+
`https://api.heygen.com/v1/video_status.get?video_id=${video_id}`,
176+
{
177+
headers: {
178+
accept: 'application/json',
179+
'content-type': 'application/json',
180+
'x-api-key': apiKey,
181+
},
182+
}
183+
)
184+
).json();
166185

167186
if (status === 'completed') {
168187
return video_url;

0 commit comments

Comments
 (0)