Skip to content

Commit

Permalink
restructure game and rooms, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
howardchung committed Dec 28, 2024
1 parent 8b7e225 commit b13f8eb
Show file tree
Hide file tree
Showing 13 changed files with 1,603 additions and 1,566 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ A website for playing Jeopardy! together with friends over the Internet. Designe
- Games might be incomplete if some clues weren't revealed on the show.

## Updating Clues:

- Game data is collected using a separate j-archive-parser project and collected into a single gzipped JSON file, which this project can retrieve.

## Environment Variables

- `REDIS_URL`: Provide to allow persisting rooms to Redis so they survive server reboots
- `OPENAI_SECRET_KEY`: Provide to allow using OpenAI's ChatGPT to judge answers

Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@types/cors": "^2.8.13",
"@types/express": "^5.0.0",
"@types/node": "^18.13.0",
"@types/papaparse": "^5.3.15",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.10",
"prettier": "^3.1.1",
Expand Down
71 changes: 71 additions & 0 deletions server/aivoice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import nodeCrypto from 'node:crypto';

// Given input text, gets back an mp3 file URL
// We can send this to each client and have it be read
// The RVC server caches for repeated inputs, so duplicate requests are fast
// Without GPU acceleration this is kinda slow to do in real time, so we may need to add support to pre-generate audio clips for specific game
export async function genAITextToSpeech(
rvcHost: string,
text: string,
): Promise<string | undefined> {
if (text.length > 10000 || !text.length) {
return;
}
const resp = await fetch(rvcHost + '/gradio_api/call/partial_36', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
data: [
text,
'Trebek',
'en-US-ChristopherNeural',
0,
0,
0,
0,
0,
['rmvpe'],
0.5,
3,
0.25,
0.33,
128,
true,
false,
1,
true,
0.7,
'contentvec',
'',
0,
0,
44100,
'mp3',
nodeCrypto.createHash('md5').update(text).digest('hex'),
],
}),
});
const info = await resp.json();
// console.log(info);
// Fetch the result
const fetchUrl = rvcHost + '/gradio_api/call/partial_36/' + info.event_id;
// console.log(fetchUrl);
const resp2 = await fetch(fetchUrl);
const info2 = await resp2.text();
// console.log(info2);
const lines = info2.split('\n');
// Find the line after complete
const completeIndex = lines.indexOf('event: complete');
const target = lines[completeIndex + 1];
if (target.startsWith('data: ')) {
// Take off the prefix, parse the array as json and get the first element
const arr = JSON.parse(target.slice(6));
// Fix the path /grad/gradio_api/file to /gradio_api/file
const url = arr[0].url.replace('/grad/gradio_api/file', '/gradio_api/file');
// console.log(url);
return url;
}
return;
}
Loading

0 comments on commit b13f8eb

Please sign in to comment.