met4citizen / TalkingHead

Talking Head (3D): A JavaScript class for real-time lip-sync using Ready Player Me full-body 3D avatars.
MIT License
350 stars 108 forks source link

Minimal Code example html fails with "AudioContext suspended" #8

Closed vishnumadhu365 closed 8 months ago

vishnumadhu365 commented 8 months ago

Facing the below error while trying the Minimal Code sample html.

image


https://goo.gl/7K7WLu --> suggests we might have to create some click activity before initializing AudioContext.

Amazing work with TalkingHead !!!

met4citizen commented 8 months ago

The first message is merely a notice or warning that can't be avoided. The warning appears because the TalkingHead class initializes the AudioContext before the document has received any user gesture. This type of initialization is permitted, but some browsers still give this notice to inform us about their policy, which restricts the app from playing audio before the first user interaction. The class follows the instruction and internally tries to call resume before initiating any audio playback.

The "Can't play audio" message, however, suggests that there is indeed a call to the speakText or speakAudio method before the user has interacted with the app, thus breaking the browser policy. I couldn't reproduce that error with the Minimal code, and in the original code the only call to speakText is inside the click event handler, which is a user action.

Did you make any changes to the example code? - If you did, you have to make sure that the user has interacted with the app in some way before calling speakText or speakAudio.

met4citizen commented 8 months ago

I just changed the log message when the AudioContext resume fails, so that the reason for the error is a bit clearer. The change will be in the upcoming release. Thank you for bringing this to my attention. I will close this issue, but feel free to ask further questions, if any.