Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lipsync using blob instead of mp3 file #137

Open
eusthace811 opened this issue Mar 26, 2024 · 4 comments
Open

Lipsync using blob instead of mp3 file #137

eusthace811 opened this issue Mar 26, 2024 · 4 comments

Comments

@eusthace811
Copy link

Hi,

I can see that you are going to soon merge and add the option for Lipsync using audio file mp3.

Is there a way that we could add Lipsync using blob data instead of a file?

Thanks and great lib!

@guansss
Copy link
Owner

guansss commented Mar 26, 2024

Hi, thanks for your interest in the library!

To play an audio blob, you need to generate a URL form it. There are two ways I can think of:

  1. Use the URL.createObjectURL() method.
  2. Convert the blob to a base64 string and use the data: scheme to create a URL, like data:audio/mp3;base64,....

After you have the URL, you can pass it to the speak() method like you would with a file URL.

@eusthace811
Copy link
Author

Thanks a lot for your help. Not sure if I know how to convert the blob to a base64 string, but I will try to find how.

Also, Is there a way to know when the audio ended and is not playing anymore?

Something like:

model.addEventListener("ended", () => {

});

@guansss
Copy link
Owner

guansss commented Mar 27, 2024

Yes, basically you can access the audio element right after starting a lip sync:

const success = await model.speak(someUrl)

if (success) {
  model.internalModel.lipSync.currentAudio.addEventListener("ended", () => {})
}

currentAudio only exists during playback, and will become undefined when the ended event is fired.

@RaSan147
Copy link

Thanks a lot for your help. Not sure if I know how to convert the blob to a base64 string, but I will try to find how.

It also supports all url, blob and b64, so you can pick your choice and use here.
Happy coding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants