Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 0084432

Browse files
committed
Add speakBack experiment
1 parent 90271e6 commit 0084432

File tree

2 files changed

+106
-73
lines changed

2 files changed

+106
-73
lines changed

app/pages/captioner.vue

+103-73
Original file line numberDiff line numberDiff line change
@@ -246,91 +246,121 @@ export default {
246246
});
247247
sequence++;
248248
};
249-
RemoteEventBus.$on('sendMutationToReceivers', ({ mutation, payload }) => {
250-
if (
251-
this.$store.state.settings.integrations.webhooks.on &&
252-
mutation === 'captioner/APPEND_TRANSCRIPT_STABILIZED'
253-
) {
254-
callWebhook({
255-
url: this.$store.state.settings.integrations.webhooks.url,
256-
method: this.$store.state.settings.integrations.webhooks.method,
257-
transcript: payload ? payload.transcript : '',
258-
});
259-
lastWebhookEventDate = Date.now();
260-
}
261249
262-
if (
263-
mutation === 'captioner/SET_TRANSCRIPT_INTERIM' &&
264-
Date.now() - lastWebhookEventDate >= 100
265-
) {
250+
RemoteEventBus.$on(
251+
'sendMutationToReceivers',
252+
async ({ mutation, payload }) => {
266253
if (
267-
this.$store.state.settings.share.roomId &&
268-
this.$store.state.socket.isConnected &&
269-
this.$store.state.settings.share.on
254+
this.$store.state.settings.integrations.webhooks.on &&
255+
mutation === 'captioner/APPEND_TRANSCRIPT_STABILIZED'
270256
) {
271-
this.$socket.sendObj({
272-
action: 'mutation',
273-
mutation,
274-
payload,
257+
callWebhook({
258+
url: this.$store.state.settings.integrations.webhooks.url,
259+
method: this.$store.state.settings.integrations.webhooks.method,
260+
transcript: payload ? payload.transcript : '',
275261
});
276262
lastWebhookEventDate = Date.now();
277263
}
278-
}
279264
280-
if (
281-
[
282-
'captioner/APPEND_TRANSCRIPT_FINAL',
283-
'captioner/CLEAR_TRANSCRIPT_INTERIM',
284-
'captioner/CLEAR_TRANSCRIPT',
265+
if (
266+
mutation === 'captioner/SET_TRANSCRIPT_INTERIM' &&
267+
Date.now() - lastWebhookEventDate >= 100
268+
) {
269+
if (
270+
this.$store.state.settings.share.roomId &&
271+
this.$store.state.socket.isConnected &&
272+
this.$store.state.settings.share.on
273+
) {
274+
this.$socket.sendObj({
275+
action: 'mutation',
276+
mutation,
277+
payload,
278+
});
279+
lastWebhookEventDate = Date.now();
280+
}
281+
}
285282
286-
'SET_TEXT_COLOR',
287-
'SET_TEXT_COLOR_INTERIM',
288-
'SET_FONT_FAMILY',
289-
'SET_FONT_VARIANT',
290-
'SET_TEXT_SIZE',
291-
'SET_LINE_HEIGHT',
292-
'SET_LETTER_SPACING',
293-
'SET_TEXT_TRANSFORM',
294-
'SET_SHADOW_COLOR',
295-
'SET_SHADOW_OPACITY',
296-
'SET_SHADOW_BLUR_RADIUS',
297-
'SET_SHADOW_OFFSET_X',
298-
'SET_SHADOW_OFFSET_Y',
299-
'SET_BACKGROUND_COLOR',
300-
'SET_BACKGROUND_OPACITY',
301-
'SET_ALIGNMENT_HORIZONTAL',
302-
'SET_ALIGNMENT_VERTICAL',
303-
'SET_ALIGNMENT_PADDING',
304-
].includes(mutation)
305-
) {
306283
if (
307-
this.$store.state.settings.share.roomId &&
308-
this.$store.state.socket.isConnected
284+
[
285+
'captioner/APPEND_TRANSCRIPT_FINAL',
286+
'captioner/CLEAR_TRANSCRIPT_INTERIM',
287+
'captioner/CLEAR_TRANSCRIPT',
288+
289+
'SET_TEXT_COLOR',
290+
'SET_TEXT_COLOR_INTERIM',
291+
'SET_FONT_FAMILY',
292+
'SET_FONT_VARIANT',
293+
'SET_TEXT_SIZE',
294+
'SET_LINE_HEIGHT',
295+
'SET_LETTER_SPACING',
296+
'SET_TEXT_TRANSFORM',
297+
'SET_SHADOW_COLOR',
298+
'SET_SHADOW_OPACITY',
299+
'SET_SHADOW_BLUR_RADIUS',
300+
'SET_SHADOW_OFFSET_X',
301+
'SET_SHADOW_OFFSET_Y',
302+
'SET_BACKGROUND_COLOR',
303+
'SET_BACKGROUND_OPACITY',
304+
'SET_ALIGNMENT_HORIZONTAL',
305+
'SET_ALIGNMENT_VERTICAL',
306+
'SET_ALIGNMENT_PADDING',
307+
].includes(mutation)
309308
) {
310-
this.$socket.sendObj({
311-
action: 'mutation',
312-
mutation,
313-
payload,
314-
});
309+
if (
310+
this.$store.state.settings.share.roomId &&
311+
this.$store.state.socket.isConnected
312+
) {
313+
this.$socket.sendObj({
314+
action: 'mutation',
315+
mutation,
316+
payload,
317+
});
318+
}
315319
}
316-
}
317-
if (
318-
[
319-
'captioner/APPEND_TRANSCRIPT_FINAL',
320-
'captioner/SET_CAPTIONER_OFF',
321-
'captioner/APPEND_TRANSCRIPT_STABILIZED',
322-
].includes(mutation) &&
323-
this.$store.state.settings.integrations.dropbox.accessToken &&
324-
this.$store.state.captioner.transcript.final
325-
) {
326-
if ('captioner/SET_CAPTIONER_OFF' === mutation) {
327-
// immediate
328-
this.$store.dispatch('SAVE_TO_DROPBOX');
329-
} else {
330-
this.saveToDropboxThrottled();
320+
if (
321+
[
322+
'captioner/APPEND_TRANSCRIPT_FINAL',
323+
'captioner/SET_CAPTIONER_OFF',
324+
'captioner/APPEND_TRANSCRIPT_STABILIZED',
325+
].includes(mutation) &&
326+
this.$store.state.settings.integrations.dropbox.accessToken &&
327+
this.$store.state.captioner.transcript.final
328+
) {
329+
if ('captioner/SET_CAPTIONER_OFF' === mutation) {
330+
// immediate
331+
this.$store.dispatch('SAVE_TO_DROPBOX');
332+
} else {
333+
this.saveToDropboxThrottled();
334+
}
335+
}
336+
337+
if (
338+
[
339+
'captioner/APPEND_TRANSCRIPT_FINAL',
340+
// 'captioner/APPEND_TRANSCRIPT_STABILIZED',
341+
].includes(mutation) &&
342+
this.experiments.includes('speakBack')
343+
) {
344+
const voices = await new Promise((resolve) => {
345+
let voices = speechSynthesis.getVoices();
346+
if (voices.length) {
347+
resolve(voices);
348+
return;
349+
}
350+
speechSynthesis.onvoiceschanged = () => {
351+
voices = speechSynthesis.getVoices();
352+
resolve(voices);
353+
};
354+
});
355+
let utterance = new SpeechSynthesisUtterance(payload.transcriptFinal);
356+
357+
utterance.voice = voices.find(
358+
(voice) => voice.name === 'Google US English'
359+
);
360+
window.speechSynthesis.speak(utterance);
331361
}
332362
}
333-
});
363+
);
334364
335365
// Zoom integration
336366
let zoomTranscriptBuffer = [];
@@ -665,4 +695,4 @@ export default {
665695
}, 1000 * 30),
666696
},
667697
};
668-
</script>
698+
</script>

app/pages/captioner/settings/experiments/index.vue

+3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ export default {
216216
return 'Save transcript with timings to Dropbox.';
217217
case 'zoom':
218218
return 'Test Zoom integration. Once enabled, go to the Zoom tab in settings.';
219+
case 'speakBack':
220+
return 'Speak words back using browser speech synthesis.';
219221
default:
220222
return '';
221223
}
@@ -228,6 +230,7 @@ export default {
228230
'science',
229231
'saveTranscriptWithTimingsToDropbox',
230232
'zoom',
233+
'speakBack',
231234
].includes(this.experimentName);
232235
},
233236
addExperiment: function({ withConfirmation }) {

0 commit comments

Comments
 (0)