feat: #3110 add voice control

This commit is contained in:
Yidadaa
2023-11-14 03:42:23 +08:00
parent 9da455a7ea
commit d1d8b1f393
13 changed files with 273 additions and 9 deletions

View File

@@ -303,5 +303,28 @@ export class ChatGPTApi implements LLMApi {
available: true,
}));
}
public cache: Record<string, ArrayBuffer> = {};
async speech(input: string): Promise<ArrayBuffer> {
if (this.cache[input]) return this.cache[input].slice(0);
const res = await fetch(this.path(OpenaiPath.Speech), {
method: "POST",
headers: {
...getHeaders(),
},
body: JSON.stringify({
model: "tts-1",
input: input,
voice: "onyx",
}),
});
const arrayBuffer = await res.arrayBuffer();
this.cache[input] = arrayBuffer.slice(0);
return arrayBuffer;
}
}
export { OpenaiPath };