mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-15 13:33:43 +08:00
feat: openai realtime merge
This commit is contained in:
48
public/audio-processor.js
Normal file
48
public/audio-processor.js
Normal file
@@ -0,0 +1,48 @@
|
||||
// @ts-nocheck
|
||||
class AudioRecorderProcessor extends AudioWorkletProcessor {
|
||||
constructor() {
|
||||
super();
|
||||
this.isRecording = false;
|
||||
this.bufferSize = 2400; // 100ms at 24kHz
|
||||
this.currentBuffer = [];
|
||||
|
||||
this.port.onmessage = (event) => {
|
||||
if (event.data.command === "START_RECORDING") {
|
||||
this.isRecording = true;
|
||||
} else if (event.data.command === "STOP_RECORDING") {
|
||||
this.isRecording = false;
|
||||
|
||||
if (this.currentBuffer.length > 0) {
|
||||
this.sendBuffer();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
sendBuffer() {
|
||||
if (this.currentBuffer.length > 0) {
|
||||
const audioData = new Float32Array(this.currentBuffer);
|
||||
this.port.postMessage({
|
||||
eventType: "audio",
|
||||
audioData: audioData,
|
||||
});
|
||||
this.currentBuffer = [];
|
||||
}
|
||||
}
|
||||
|
||||
process(inputs) {
|
||||
const input = inputs[0];
|
||||
if (input.length > 0 && this.isRecording) {
|
||||
const audioData = input[0];
|
||||
|
||||
this.currentBuffer.push(...audioData);
|
||||
|
||||
if (this.currentBuffer.length >= this.bufferSize) {
|
||||
this.sendBuffer();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
registerProcessor("audio-recorder-processor", AudioRecorderProcessor);
|
||||
17
public/plugins.json
Normal file
17
public/plugins.json
Normal file
@@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"id": "dalle3",
|
||||
"name": "Dalle3",
|
||||
"schema": "https://ghp.ci/https://raw.githubusercontent.com/ChatGPTNextWeb/NextChat-Awesome-Plugins/main/plugins/dalle/openapi.json"
|
||||
},
|
||||
{
|
||||
"id": "arxivsearch",
|
||||
"name": "ArxivSearch",
|
||||
"schema": "https://ghp.ci/https://raw.githubusercontent.com/ChatGPTNextWeb/NextChat-Awesome-Plugins/main/plugins/arxivsearch/openapi.json"
|
||||
},
|
||||
{
|
||||
"id": "duckduckgolite",
|
||||
"name": "DuckDuckGoLiteSearch",
|
||||
"schema": "https://ghp.ci/https://raw.githubusercontent.com/ChatGPTNextWeb/NextChat-Awesome-Plugins/main/plugins/duckduckgolite/openapi.json"
|
||||
}
|
||||
]
|
||||
@@ -15,6 +15,10 @@ self.addEventListener("install", function (event) {
|
||||
);
|
||||
});
|
||||
|
||||
function jsonify(data) {
|
||||
return new Response(JSON.stringify(data), { headers: { 'content-type': 'application/json' } })
|
||||
}
|
||||
|
||||
async function upload(request, url) {
|
||||
const formData = await request.formData()
|
||||
const file = formData.getAll('file')[0]
|
||||
@@ -33,13 +37,13 @@ async function upload(request, url) {
|
||||
'server': 'ServiceWorker',
|
||||
}
|
||||
}))
|
||||
return Response.json({ code: 0, data: fileUrl })
|
||||
return jsonify({ code: 0, data: fileUrl })
|
||||
}
|
||||
|
||||
async function remove(request, url) {
|
||||
const cache = await caches.open(CHATGPT_NEXT_WEB_FILE_CACHE)
|
||||
const res = await cache.delete(request.url)
|
||||
return Response.json({ code: 0 })
|
||||
return jsonify({ code: 0 })
|
||||
}
|
||||
|
||||
self.addEventListener("fetch", (e) => {
|
||||
@@ -56,4 +60,3 @@ self.addEventListener("fetch", (e) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user