Skip to content

Commit

Permalink
[1.5.0]
Browse files Browse the repository at this point in the history
  • Loading branch information
Quskia committed Apr 25, 2023
1 parent be80beb commit 1446128
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
43 changes: 36 additions & 7 deletions discordChatGPTVoiceBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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.");
Expand All @@ -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
Expand Down Expand Up @@ -351,6 +374,7 @@ console.log('Package version: ' + VERSION);
triggerRandomly();
console.log("--------------------------------------------------")


//get number of members in the voice channel


Expand Down Expand Up @@ -392,3 +416,8 @@ client.on('messageCreate', message => { // when there is a message sent
}*/
})
client.login(process.env.BOT_TOKEN);





1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions ssml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<speak version="1.0" xmlns="https://www.w3.org/2001/10/synthesis" xml:lang="en-US">
<voice name="en-US-JennyNeural">
When you're on the freeway, it's a good idea to use a GPS.
</voice>
</speak>

0 comments on commit 1446128

Please sign in to comment.