Skip to content

Commit

Permalink
fixed bug, add icon
Browse files Browse the repository at this point in the history
  • Loading branch information
SchneeHertz committed Mar 17, 2023
1 parent 9df3187 commit 6201c5e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
43 changes: 19 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,8 @@ const speakPrompt = (text, audioFilename, triggerRecord) => {
async result => {
synthesizer.close()
await sound.play(audioPath)
if (triggerRecord && STATUS.isSpeechTalk) triggerSpeech()
resolveSpeakTextList()
if (triggerRecord && STATUS.isSpeechTalk) {
STATUS.isRecording = true
getSpeechText(openai, SPEECH_AUDIO_PATH)
.then(adminTalk=>{
STATUS.isRecording = false
messageLogAndSend({
id: nanoid(),
from: `(${ADMIN_NAME})`,
text: adminTalk
})
resloveAdminPrompt({prompt: adminTalk, triggerRecord: true})
})
}
},
error => {
console.log(error)
Expand Down Expand Up @@ -154,7 +142,7 @@ const resloveAdminPrompt = async ({prompt, triggerRecord})=> {
history.conversationHistory = _.takeRight(history.conversationHistory, 20)
history.useHistory += 1
fs.writeFileSync(path.join(STORE_PATH, 'history.json'), JSON.stringify(history, null, ' '), {encoding: 'utf-8'})
if (history.useHistory >= history.conversationLimit) {
if (history.useHistory >= history.limitHistory.conversationLimit) {
updateMemory()
}
messageLogAndSend({
Expand Down Expand Up @@ -190,11 +178,25 @@ const updateMemory = ()=>{
messages
})
.then(async res=>{
history.memory = res.data.choices[0].message.content
history.memory = res.data.choices[0].message.content.slice(0, history.limitHistory.memoryLength)
fs.writeFileSync(path.join(STORE_PATH, 'history.json'), JSON.stringify(history, null, ' '), {encoding: 'utf-8'})
})
}

const triggerSpeech = async ()=>{
STATUS.isRecording = true
mainWindow.setProgressBar(100, {mode: 'indeterminate'})
let adminTalk = await getSpeechText(openai, SPEECH_AUDIO_PATH)
STATUS.isRecording = false
mainWindow.setProgressBar(-1)
messageLogAndSend({
id: nanoid(),
from: `(${ADMIN_NAME})`,
text: adminTalk
})
resloveAdminPrompt({prompt: adminTalk, triggerRecord: true})
}

setInterval(()=>mainWindow.webContents.send('send-status', STATUS), 1000)
ipcMain.handle('send-prompt', async (event, text)=>{
resloveAdminPrompt({prompt: text})
Expand All @@ -207,15 +209,8 @@ ipcMain.handle('open-config', async (event)=>{
})
ipcMain.handle('switch-speech-talk', async ()=>{
STATUS.isSpeechTalk = !STATUS.isSpeechTalk
mainWindow.setProgressBar(-1)
if (STATUS.isSpeechTalk) {
STATUS.isRecording = true
let adminTalk = await getSpeechText(openai, SPEECH_AUDIO_PATH)
STATUS.isRecording = false
messageLogAndSend({
id: nanoid(),
from: `(${ADMIN_NAME})`,
text: adminTalk
})
resloveAdminPrompt({prompt: adminTalk, triggerRecord: true})
triggerSpeech()
}
})
2 changes: 1 addition & 1 deletion modules/speech.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { nanoid } = require('nanoid')
let recordPromise = (SPEECH_AUDIO_PATH)=>{
let audioFilePath = path.join(SPEECH_AUDIO_PATH, nanoid() + '.mp3')
return new Promise((resolve, reject)=>{
const spawned = spawn('sox', ['-d', '-t', 'mp3', audioFilePath, 'silence', 1, 0.1, '3%', 1, 3.0, '3%'])
const spawned = spawn('sox', ['-d', '-t', 'mp3', audioFilePath, 'silence', '1', '0.1', '3%', '1', '3.0', '3%'])
spawned.on('error', data=>{
reject(data)
})
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"win": {
"target": [
"nsis"
]
],
"icon": "public/icon.ico"
}
},
"devDependencies": {
Expand Down
Binary file added public/icon.ico
Binary file not shown.

0 comments on commit 6201c5e

Please sign in to comment.