Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
SchneeHertz committed Aug 17, 2023
1 parent b167efc commit 5fee03a
Show file tree
Hide file tree
Showing 10 changed files with 2,565 additions and 144 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ devtools
audio/*.wav
speakAudio/*
log/*.txt
resources/extraResources/_models
resources/extraResources/_models/faster-whisper-large-v2/config.json
resources/extraResources/_models/faster-whisper-large-v2/model.bin
resources/extraResources/_models/faster-whisper-large-v2/tokenizer.json
resources/extraResources/_models/faster-whisper-large-v2/vocabulary.txt
resources/extraResources/cublas64_11.dll
resources/extraResources/cublasLt64_11.dll
resources/extraResources/cudnn_cnn_infer64_8.dll
Expand Down
6 changes: 3 additions & 3 deletions modules/edge-tts.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { spawn } = require('node:child_process')
const { config } = require('../utils/initFile.js')
const { config } = require('../utils/loadConfig.js')

let ttsPromise = (text, audioPath, SpeechSynthesisVoiceName = 'zh-CN-XiaoyiNeural')=>{
let ttsPromise = (text, audioPath)=>{
let vttPath = audioPath + '.vtt'
return new Promise((resolve, reject)=>{
const spawned = spawn('edge-tts', [
'-v', SpeechSynthesisVoiceName,
'-v', config.SpeechSynthesisVoiceName,
'--text', text,
'--write-media', audioPath,
'--write-subtitles', vttPath,
Expand Down
71 changes: 71 additions & 0 deletions modules/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const google = require('@schneehertz/google-it')
const { config } = require('../utils/loadConfig.js')

const functionInfo = [
{
"name": "getInformationFromGoogle",
"description": "Fetch information from Google based on a query string",
"parameters": {
"type": "object",
"properties": {
"queryString": {
"type": "string",
"description": "The search term to lookup",
},
},
"required": ["queryString"],
}
},
{
"name": "getHistoricalConversationContent",
"description": "Searching historical conversation content in conversation history.",
"parameters": {
"type": "object",
"properties": {
"relatedText": {
"type": "string",
"description": "The related text to find historical conversation content",
},
},
"required": ["relatedText"],
}
},
]

const functionAction = {
getInformationFromGoogle ({queryString}) {
return `休留正在搜索${queryString}`
},
getHistoricalConversationContent ({relatedText}) {
return `休留想起了关于${relatedText}的事情`
}
}

const getInformationFromGoogle = async ({queryString}) => {
let options = { proxy: config.proxyString }
let additionalQueryParam = {
lr: 'lang_zh-CN',
hl: 'zh-CN',
cr: 'countryCN',
gl: 'cn',
safe: 'high'
}
let googleRes = await google({options, disableConsole: true, query: queryString, limit: 6, additionalQueryParam})
// return googleRes.map(r=>r.snippet).join('\n').slice(0, 800)
return JSON.stringify(googleRes)
}

const getHistoricalConversationContent = async ({relatedText, dbTable}) => {
let MemoryTexts = await dbTable.search(relatedText).limit(2).execute()
return MemoryTexts.map(s=>s.text).join('\n')
}


module.exports = {
functionInfo,
functionAction,
functionList: {
getInformationFromGoogle,
getHistoricalConversationContent
}
}
10 changes: 9 additions & 1 deletion modules/speech.js → modules/record.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const { app } = require('electron')
const { spawn } = require('node:child_process')
const path = require('node:path')
const fs = require('node:fs')
const { nanoid } = require('nanoid')
const { SPEECH_AUDIO_PATH } = require('../utils/initFile.js')


let STORE_PATH = app.getPath('userData')
if (!fs.existsSync(STORE_PATH)) {
fs.mkdirSync(STORE_PATH)
}
const SPEECH_AUDIO_PATH = path.join(STORE_PATH, 'speechAudio')

const sox = path.join(process.cwd(), 'resources/extraResources/sox.exe')
const recordPromise = ()=>{
Expand Down
33 changes: 33 additions & 0 deletions modules/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { app } = require('electron')
const path = require('node:path')
const fs = require('node:fs')

let STORE_PATH = app.getPath('userData')
if (!fs.existsSync(STORE_PATH)) {
fs.mkdirSync(STORE_PATH)
}

let storeData
try {
storeData = JSON.parse(fs.readFileSync(path.join(STORE_PATH, 'storeData.json'), {encoding: 'utf-8'}))
} catch {
storeData = {
history: []
}
fs.writeFileSync(path.join(STORE_PATH, 'storeData.json'), JSON.stringify(storeData, null, ' '), {encoding: 'utf-8'})
}

const getStore = (key, defaultValue)=>{
return storeData[key] || defaultValue
}

const setStore = (key, value)=>{
storeData[key] = value
fs.writeFileSync(path.join(STORE_PATH, 'storeData.json'), JSON.stringify(storeData, null, ' '), {encoding: 'utf-8'})
}

module.exports = {
getStore,
setStore
}

2 changes: 1 addition & 1 deletion modules/whisper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { spawn } = require('node:child_process')
const path = require('node:path')
const fs = require('node:fs')
const { recordPromise } = require('./speech.js')
const { recordPromise } = require('./record.js')

const whisper = path.join(process.cwd(), 'resources/extraResources/whisper-faster.exe')

Expand Down

0 comments on commit 5fee03a

Please sign in to comment.