Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subtitles poc #71

Merged
merged 4 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions assets/animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,41 @@ class Animator {
}
}

class CaptionManager {
constructor() {
this.elt = document.getElementById('captions');
}

setCaption(caption) {
this.elt.innerText = caption;
this.show();
}

show() {
this.elt.style.display = 'block';
}

hide() {
this.elt.style.display = 'none';
}

clear() {
this.elt.innerText = '';
this.hide();
}
}

const animator = new Animator();
const captionManager = new CaptionManager();
const socket = io('http://127.0.0.1:11434');

socket.on('status', (status) => {
animator.setState(status);
});
socket.on('caption', (caption) => {
if (caption.status === 'start') {
captionManager.setCaption(caption.content);
} else {
captionManager.clear();
}
});
26 changes: 25 additions & 1 deletion assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
<script src="sketch.js" defer></script>
<title>P5.JS Sketch</title>
<style>
* {
/* box-sizing: border-box; */
}
body {
/* height: 90vh; */
}

#matt-animator {
position: absolute;
top: 10px;
Expand All @@ -26,6 +33,22 @@
transform-origin: 50% 100%;
}

#captions {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
text-align: center;

background-color: rgba(0, 0, 0, 0.75);
border-radius: 10px;
border: 2px solid black;
padding: 10px;
color: white;
font-family: sans-serif;
font-size: large;
}

/* Talking animation using rotation */
@keyframes talking {
0% {
Expand Down Expand Up @@ -67,6 +90,7 @@
</style>
</head>
<body style="position: relative">
<img src="/matt-pending.png" id="matt-animator" ="Google Logo" />
<img src="/matt-pending.png" id="matt-animator" />
<div id="captions" style="display: none">Captions go here</div>
</body>
</html>
3 changes: 2 additions & 1 deletion config.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module.exports = {
model: 'replicate', // replicate, ollama, openai, gemini
socketServerPort: 11434, // Port for the socket server
tts: 'piper', // say, coqui, piper, elevenlabs, playht
showSubtitles: false, // show subtitles of what is being said
replicateApiToken: 'your-replicate-api-token-here',
openAIApiToken: 'your-openai-api-token-here',
geminiApiToken: 'your-gemini-api-token-here',
Expand All @@ -17,5 +19,4 @@ module.exports = {
secret: 'your-playht-secret-here',
userId: 'your-playht-user-id-here',
},
tts: 'piper', // say, coqui, piper, elevenlabs
};
6 changes: 3 additions & 3 deletions package-lock.json

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

1 change: 0 additions & 1 deletion src/commands/setupFiles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Command = require('../lib/command');
const { createFile, copyFile } = require('../util/createFile');
const fs = require('fs');
const path = require('path');

class SetupFilesCommand extends Command {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/agent/Agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,13 @@ class Agent {
setStatusbarText('$(record-keys) Writing code...');
await applyDiffs(editor, diffs);
} else if (step.type === 'SPEAK') {
let content = step.content.trim();
if (!content) return;
this.webserver.sendStatus('talking');
this.webserver.sendCaption({ status: 'start', content: content });
setStatusbarText('$(mic) Talking...');
await speak(step.content);
await speak(content);
this.webserver.sendCaption({ status: 'end' });
}
this.previousAction = step.type;
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/web/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class SocketServer {
this.status = status;
this.io.emit('status', status);
}

sendCaption(caption) {
if (config.showSubtitles) this.io.emit('caption', caption);
}
}

module.exports = {
Expand Down
4 changes: 3 additions & 1 deletion src/util/createFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ async function copyFile(source, path) {
const activeFolder = vscode.workspace.workspaceFolders[0];
const filePath = vscode.Uri.joinPath(activeFolder.uri, path);
const sourcePath = vscode.Uri.file(source);
await vscode.workspace.fs.copy(sourcePath, filePath);
await vscode.workspace.fs.copy(sourcePath, filePath, {
overwrite: true,
});
return {
path: filePath,
open: async () => {
Expand Down