From 1446128e81bcfd59dcc933e7e3423e3ccd0f8b45 Mon Sep 17 00:00:00 2001 From: Quskia Date: Tue, 25 Apr 2023 17:41:50 +0100 Subject: [PATCH] [1.5.0] --- discordChatGPTVoiceBot.js | 43 ++++++++++++++++++++++++++++++++------- package.json | 1 + ssml.xml | 5 +++++ 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 ssml.xml diff --git a/discordChatGPTVoiceBot.js b/discordChatGPTVoiceBot.js index d162d4c..abc9673 100644 --- a/discordChatGPTVoiceBot.js +++ b/discordChatGPTVoiceBot.js @@ -21,6 +21,9 @@ const { addSpeechEvent } = require("discord-speech-recognition"); const { joinVoiceChannel } = require('@discordjs/voice'); const { createAudioPlayer } = require('@discordjs/voice'); const { createAudioResource, AudioPlayerStatus } = require('@discordjs/voice'); +const sdk = require("microsoft-cognitiveservices-speech-sdk"); + + var fs = require('fs'); const parse = require("@fortaine/fetch-event-source/parse"); const { Configuration, OpenAIApi } = require("openai"); @@ -108,14 +111,35 @@ profanityFilter: false, function saveTextStream(textToSpeak, callback) { + + const speechConfig = sdk.SpeechConfig.fromSubscription(process.env.SPEECH_KEY, process.env.SPEECH_REGION); + speechConfig.speechSynthesisVoiceName = "pt-BR-GiovannaNeural"; + const speechSynthesizer = new sdk.SpeechSynthesizer(speechConfig); + + console.log("Azure TTS:") + speechSynthesizer.speakTextAsync( + textToSpeak, + result => { + const { audioData } = result; + speechSynthesizer.close(); + + // convert arrayBuffer to stream + const bufferStream = new PassThrough(); + bufferStream.end(Buffer.from(audioData)); + callback(bufferStream); + //return bufferStream; + }, + error => { + console.log("ERROR") + console.log(error); + speechSynthesizer.close(); + }); + + try { - var gtts = new gTTS(textToSpeak, gTTSLanguage,tld="pt",2); - - //Create stream instead of saving to file - var audioStream = gtts.stream(); - + // Call the callback function with the audio stream - callback(audioStream); + } catch(err) { console.log("Not able to read text, try again."); @@ -142,7 +166,6 @@ async function chatgpt_start(){ selfMute: false }) chatgpt({"role": "system", "content": "Then, continue as Vanessa language model. Ela deve responder com respostas curtas, usando poucas palavras,terminando com um palavrão. Ela acabou de aterrar num canal de voz e deve saudar os membros. \n"},"False"); - } //remove keywork from string message @@ -351,6 +374,7 @@ console.log('Package version: ' + VERSION); triggerRandomly(); console.log("--------------------------------------------------") + //get number of members in the voice channel @@ -392,3 +416,8 @@ client.on('messageCreate', message => { // when there is a message sent }*/ }) client.login(process.env.BOT_TOKEN); + + + + + diff --git a/package.json b/package.json index d4f09e4..91940f3 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "express": "^4.18.2", "ffmpeg-static": "^5.1.0", "gtts": "^0.2.1", + "microsoft-cognitiveservices-speech-sdk": "^1.27.0", "openai": "^3.2.0" }, "scripts": { diff --git a/ssml.xml b/ssml.xml new file mode 100644 index 0000000..9c60cf3 --- /dev/null +++ b/ssml.xml @@ -0,0 +1,5 @@ + + + When you're on the freeway, it's a good idea to use a GPS. + + \ No newline at end of file