-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBard Speaks.user.js
More file actions
45 lines (37 loc) · 1.47 KB
/
Bard Speaks.user.js
File metadata and controls
45 lines (37 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// ==UserScript==
// @name Bard Speaks
// @namespace http://geor9.com
// @version 0.1
// @description Automatically play synthesized speech of Bards response. Requires Bard for Google extension https://chrome.google.com/webstore/detail/bard-for-google/hnadleianomnjcoeplifgbkiejchjmah . You'll need to delete *bardo=1* from the URL match line if you want it to run by default.
// @author George
// @match https://www.google.com/search?*bardo=1*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
var synth = window.speechSynthesis;
// Chrome loads voices asynchronously.
window.speechSynthesis.onvoiceschanged = function(e) {
setInterval(checkTextLength, 200);
};
function loadVoice() {
var voices = synth.getVoices();
var voice = voices.find(voice => voice.name === "Microsoft Steffan Online (Natural) - English (United States)");
var utterance = new SpeechSynthesisUtterance(document.getElementById("bard_section_div").innerText);
utterance.voice = voice;
utterance.rate = 6;
utterance.pitch = 1.1;
utterance.volume = 1;
synth.speak(utterance);
}
//speak one time only (rather than again at setInterval)
var once = false;
//wait for bard response of at least 2 characters
function checkTextLength() {
var textLength = document.getElementById("bard_section_div").innerText.length;
if (textLength >= 2 && !once) {
loadVoice();
once = true; }}
}
)();