aws-samples / amazon-polly-metahumans

This Unreal Engine sample project demonstrates how to bring Epic Games' MetaHuman digital characters to life using the Amazon Polly text-to-speech service from AWS. Use this project as a starting point for creating your own Unreal Engine applications that leverage Amazon Polly to give voice to your MetaHumans.
MIT No Attribution
178 stars 67 forks source link

Speech component - add way to stop speech #29

Open chingizagha opened 1 year ago

chingizagha commented 1 year ago

How I can make to stop speech?

zvaehn commented 1 year ago

bump

Krxtopher commented 1 year ago

The implementation doesn't currently provide a way to stop a speech before it reaches its natural conclusion. You will have to implement your own StopSpeech() method in the SpeechComponent class.

If you do implement this feature, please consider contributing it back to this project via pull request!

zvaehn commented 1 year ago

Since i am using this just for a PoC i dont have the time right now to implement it properly. For everyone interested, i picked up @Krxtopher suggestion and implemented a hacky "StopSpeech()" function.

File: SpeecComponent.cpp

void USpeechComponent::StopSpeaking() {
    FScopeLock lock(&Mutex);

    VisemeEvent CurrentVisemeEvent;
    CurrentVisemeEvent.Viseme = GetVisemeValueFromString("sil"); // Reset to the silent visme otherwise we get stuck with the last visme
    CurrentVisemeEvent.TimeMilliseconds = 100;

    VisemeEventArray.Empty();
    VisemeEventArray.Add(CurrentVisemeEvent);
    CurrentVisemeIndex = -1; // Current Index - 1 because the Function PlayNextVisme will get invoced and increase the CurrentVisemeIndex by 1;

    return;
}

File: SpeecComponent.h

    /*
    * Stops Speaking
    */
    UFUNCTION(BlueprintCallable, Category = "Amazon Polly")
    void StopSpeaking();

Build the solution and you should be ready to get the "StopSpeaking" Function in your characters blueprint. In Case you are wondering how to stop the sound as well: i changed the "playSound2D" with "spawnSound2D" which allowed me to get a reference and simple stopping it via the soundcomponent "stop" function after calling the "StopSpeaking" method.

I am not a C++, nor an unreal developer, so i am welcome for any feedback.

kcs9303 commented 8 months ago

@zvaehn I entered the C++ you provided well, but When I run the project, it crashes. qwer

kcs9303 commented 8 months ago

Ah, it's solved. CurrentVisemeIndex = -1; It was solved by setting it to 0 instead of -1.