aao + chattykathy+amazon polly

NXR

Lt. Junior Grade
Registriert
Juli 2015
Beiträge
293
Hey Leute,

ich nutze Axis and Ohs und möchte gern polly stimmen im RPN Script einfügen und abspielen lassen.

also z.B hier sollen die (VOICE:Microsoft·Mark)·(SPEAK:) gegen polly voices ausgetauscht werden.
(VOICE:Microsoft·Mark)·(SPEAK:starting·cockpit·preparation)
1·(>K:A310-300-Light·Navlogo·Toggle)
1·(>K:A310-300-Light·Strobe·Toggle)
(SLEEP:5000)
1·(>L:A300_GNDCTL,·Number)·//1=ON
1·(>K:A310-300-elec·bat1·toggle)
1·(>K:A310-300-elec·bat2·toggle)
1·(>K:A310-300-elec·bat3·toggle)
1·(>K:A310-300-external·power·toggle)
(SLEEP:1000)
1·(>K:A310-300-adirs·1·nav)
1·(>K:A310-300-adirs·2·nav)
1·(>K:A310-300-adirs·3·nav)
1·(>K:A310-300-signs·no·smoking·switch·Toggle)
1·(>L:A310_oxygen_low_pressure_supply,·number)·//0·off·1=on
1·(>L:A310_EMER_EXIT_SWITCH,·Number)·//0=on·1=arm
(SLEEP:10000)
(VOICE:Microsoft·Mark)·(SPEAK:Engine·two·Firetest)
1·(>L:A310_Engine2_Loop_Test_switch,·Bool)
(SLEEP:5000)
0·(>L:A310_Engine2_Loop_Test_switch,·Bool)
(SLEEP:5000)
(VOICE:Microsoft·Mark)·(SPEAK:Engine·one·Firetest)
1·(>L:A310_Engine1_Loop_Test_switch,·Bool)
(SLEEP:5000)
0·(>L:A310_Engine1_Loop_Test_switch,·Bool)
(SLEEP:5000)
(VOICE:Microsoft·Mark)·(SPEAK:A·P·U·Firetest)
1·(>L:A310_APU_Loop_Test_switch,·Bool)
(SLEEP:5000)
0·(>L:A310_APU_Loop_Test_switch,·Bool)
1·(>L:A310_RESET_RUDDER_TRIM_Command,·Bool)
(SLEEP:500)
0·(>L:A310_RESET_RUDDER_TRIM_Command,·Bool)
(VOICE:Microsoft·Mark)·(SPEAK:Cockpit·Firetests·done,·Cockpit·preparation·completed)

Ich hatte gelesen, dass es gehen würde wenn man in aao eine html erstellt die wiederum per lvar den text and chattykathy https://github.com/ejbeaty/ChattyKathy sendet und dann weiter zu polly um die stimme direkt abzuspielen. ich bekomme das leider nicht hin, kann mir die wer erstellen? die aao API läuft auf http://192.168.178.20:43380
1700465760016.png
 
was sagt eine ki zu dem thema?
ich dachte die wären soweit und könnten dir so eine html datei kreieren?
 
leider nicht. oder ich bin zu blöd. ich kenne mich halt gar nicht aus mit programmieren.

gpt hat mir diese codes erstellt aber wenn ich sie öffne dann tut sich gar nichts, also nichts wird abgespielt. Die Zugangsdaten habe ich aus dem code entfernt.

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Axis and Ohs Integration with Polly</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://sdk.amazonaws.com/js/aws-sdk-2.0.0.min.js"></script>
    <script src="ChattyKathy.js"></script>
</head>
<body>
    <h1>Axis and Ohs Integration with Polly</h1>
    <script>
        $(document).ready(function() {
            // Initialisieren von ChattyKathy
            var awsCredentials = new AWS.Credentials("User", "Pass");
            var settings = {
                awsCredentials: awsCredentials,
                awsRegion: "us-east-1",
                pollyVoiceId: "Matthew",
                cacheSpeech: true
            };
            window.kathy = ChattyKathy(settings);

            // Funktion zum Abrufen und Sprechen des Textes
            var fetchAndSpeak = function() {
                let url = 'http://192.168.178.20:43380/webapi?json={"getvars": [{"var": "L:ChattyKathy_Text"}]}';

                $.get(url, function(response) {
                    let textToSpeak = response; // Text aus der Antwort extrahieren
                    if (textToSpeak) {
                        window.kathy.Speak(textToSpeak); // Text sprechen
                    }
                }).fail(function() {
                    console.error('Fehler beim Abrufen der LVar-Werte');
                });
            };

            // Regelmäßiges Abfragen einrichten
            setInterval(fetchAndSpeak, 100);
        });
    </script>
</body>
</html>

und


Javascript:
// Ersetzen Sie YOUR_ACCESS_KEY und YOUR_SECRET_KEY mit Ihren AWS-Anmeldeinformationen
var awsCredentials = new AWS.Credentials("User", "Pass");
var settings = {
    awsCredentials: awsCredentials,
    awsRegion: "us-east-1",
    pollyVoiceId: "Matthew",
    cacheSpeech: true
};

function ChattyKathy(settings) {
    settings = getValidatedSettings(settings);

    var kathy = {
        self: this,
        playlist: [],
        Speak: function (msg) {
            if (isSpeaking) {
                this.playlist.push(msg);
            } else {
                say(msg).then(sayNext);
            }
        },
        ShutUp: function(){
            shutUp();
        },
        SpeakWithPromise: function (msg) {
            return say(msg);
        },
        IsSpeaking: function () {
            return isSpeaking;
        },
        ForgetCachedSpeech: function () {
            localStorage.removeItem("chattyKathyDictionary");
        }
    };

    function shutUp() {
        isSpeaking = false;
        audioElement.pause();
        playlist = [];
    }

    function say(message) {
        return new Promise(function (successCallback, errorCallback) {
            isSpeaking = true;
            getAudio(message)
                .then(playAudio)
                .then(successCallback);
        });
    }

    function sayNext() {
        var list = kathy.playlist;
        if (list.length > 0) {
            var msg = list[0];
            list.splice(0, 1);
            say(msg).then(sayNext);
        }
    }

    function getAudio(message) {
        if (settings.cacheSpeech === false || requestSpeechFromLocalCache(message) === null) {
            return requestSpeechFromAWS(message);
        } else {
            return requestSpeechFromLocalCache(message);
        }
    }

    function requestSpeechFromAWS(message) {
        return new Promise(function (successCallback, errorCallback) {
            var polly = new AWS.Polly();
            var params = {
                OutputFormat: 'mp3',
                Text: `<speak>${message}</speak>`,
                VoiceId: settings.pollyVoiceId,
                TextType: 'ssml'
            }
            polly.synthesizeSpeech(params, function (error, data) {
                if (error) {
                    errorCallback(error)
                } else {
                    saveSpeechToLocalCache(message, data.AudioStream);
                    successCallback(data.AudioStream);
                }
            });
        });
    }

    function saveSpeechToLocalCache(message, audioStream) {
        var record = {
            Message: message,
            AudioStream: JSON.stringify(audioStream)
        };
        var localPlaylist = JSON.parse(localStorage.getItem("chattyKathyDictionary"));

        if (localPlaylist === null) {
            localPlaylist = [];
            localPlaylist.push(record);
        } else {
            localPlaylist.push(record);
        }
        localStorage.setItem("chattyKathyDictionary", JSON.stringify(localPlaylist));
    }

    function requestSpeechFromLocalCache(message) {
        var audioDictionary = localStorage.getItem("chattyKathyDictionary");
        if (audioDictionary === null) {
            return null;
        }
        var audioStreamArray = JSON.parse(audioDictionary);
        var audioStream = audioStreamArray.filter(function (record) {
            return record.Message === message;
        })[0];
        if (audioStream === null || typeof audioStream === 'undefined') {
            return null;
        } else {
            return new Promise(function (successCallback, errorCallback) {
                successCallback(JSON.parse(audioStream.AudioStream).data);
            });
        }
    }

    function playAudio(audioStream) {
        return new Promise(function (success, error) {
            var uInt8Array = new Uint8Array(audioStream);
            var arrayBuffer = uInt8Array.buffer;
            var blob = new Blob([arrayBuffer]);

            var url = URL.createObjectURL(blob);
            audioElement.src = url;
            audioElement.addEventListener("ended", function () {
                isSpeaking = false;
                success();
            });
            audioElement.play();
        });
    }

    function getValidatedSettings(settings) {
        if (typeof settings === 'undefined') {
            throw "Settings must be provided to ChattyKathy's constructor";
        }
        if (typeof settings.awsCredentials === 'undefined') {
            throw "A valid AWS Credentials object must be provided";
        }
        if (typeof settings.awsRegion === 'undefined' || settings.awsRegion.length < 1) {
            throw "A valid AWS Region must be provided";
        }
        if (typeof settings.pollyVoiceId === 'undefined') {
            settings.pollyVoiceId = "Amy";
        }
        if (typeof settings.cacheSpeech === 'undefined') {
            settings.cacheSpeech === true;
        }
        return settings;
    }

    return kathy;
}

var audioElement = document.createElement('audio');
audioElement.setAttribute("id", "audioElement" + new Date().valueOf().toString());
document.body.appendChild(audioElement);

var isSpeaking = false;
var playlist = [];

var kathy = ChattyKathy(settings);
kathy.Speak("Hallo Welt, mein Name ist Kathy!");
 
das spuckt bard aus.
vielleicht hilft dir das weiter? ich habe leider null plan



Sure, here is the HTML code that you can use to create an AAU LVAR that will send the text to ChattyKathy and then to Polly to play the voice directly:

Code:
<!DOCTYPE html>
<html>
<head>
<title>Polly Voice Playback</title>
</head>
<body>
<script>
var chattyKathyURL = "http://localhost:8080/api/chat";
var pollyURL = "https://polly.us-east-1.amazonaws.com/v1/synthesize";
var voiceID = "Joanna";
var text = "Cockpit preparation completed";

var chattyKathyRequest = new XMLHttpRequest();
chattyKathyRequest.open("POST", chattyKathyURL);
chattyKathyRequest.setRequestHeader("Content-Type", "application/json");
chattyKathyRequest.send(JSON.stringify({ text: text }));

chattyKathyRequest.onload = function() {
if (chattyKathyRequest.status === 200) {
var pollyRequest = new XMLHttpRequest();
pollyRequest.open("POST", pollyURL);
pollyRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
pollyRequest.send("OutputFormat=ogg_vorbis&Text=" + encodeURIComponent(chattyKathyRequest.responseText) + "&VoiceId=" + voiceID);

pollyRequest.onload = function() {
if (pollyRequest.status === 200) {
var audio = new Audio(pollyRequest.responseText);
audio.play();
}
};
}
};
</script>
</body>
</html>

To use this code, you will need to save it as an HTML file and then open it in your web browser. The AAU LVAR will be created and sent to ChattyKathy, which will then send the text to Polly. Polly will then play the voice directly.
 
Zurück
Oben