Skip to content
Open
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
51 changes: 29 additions & 22 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Open source comm board for all!">
<meta name="keywords" content="communication, accessibility, open source">
<!----google fonts-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;0,700;0,900;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">

<title>Talk To Me Technology</title>

<!-- external CSS link -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Open source comm board for all!">
<meta name="keywords" content="communication, accessibility, open source">
<!----google fonts-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;0,700;0,900;1,300;1,400;1,500;1,700;1,900&display=swap"
rel="stylesheet">

<title>Talk To Me Technology</title>

<!-- external CSS link -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
</head>

<body>
<h1>Talk to me Technology</h1>
<section id="mainContainer">
<select id="voiceSelect"></select>

<section id="mainContainer">

</section>

</section>
<section class="customInputWrapper">
<form id="iSaid">
<label id="customInputLabel" for="keyboard">Type custom word or phrase:</label>
<input id="keyboard" type="text" placeholder ="Example: I want to go to the park.">
<input id="keyboard" type="text" placeholder="Example: I want to go to the park.">
</form>
<a id="submitText">Submit</a>

<!-- Button for adding tiles -->
<!-- <a id="addBtn">add</a> -->
</section>
<script src="./js/data.js"></script>
<script src="./js/main.js"></script>
<script src="./js/main.js"></script>
</body>
</html>

</html>
136 changes: 89 additions & 47 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,99 @@
// globally define variables
let voice
let voices
select = document.querySelector('#voiceSelect')

//set function to populate a dropdown select tab in html with the list of getvoices method
function populateVoiceList() {
if (typeof speechSynthesis === 'undefined') {
return;
}
voices = speechSynthesis.getVoices()
for (let i = 0; i < voices.length; i++) {
let option = document.createElement('option');
option.textContent = voices[i].name + ' (' + voices[i].lang + ')';

if (voices[i].default) {
option.textContent += ' -- DEFAULT';
}

option.setAttribute('data-lang', voices[i].lang);
option.setAttribute('data-name', voices[i].name);
document.getElementById("voiceSelect").appendChild(option);
}
}

// make event listener, on change of the dropdown, the voice and lang changes to the selected name
select.addEventListener('change', event => {

voice = voices.find(({ name, lang }) => `${name} (${lang})` === event.target.value)
console.log(voices, event.target.value)
})

// call function to populate
populateVoiceList();
if (typeof speechSynthesis !== 'undefined' && speechSynthesis.onvoiceschanged !== undefined) {
speechSynthesis.onvoiceschanged = populateVoiceList;
}


function MakeNewUtterance(boxNumber, utteranceWord, imgSrc, bgColor, altText) {
this.synth1 = window.speechSynthesis;
this.sayWord = () => {
if (window.speechSynthesis.speaking) {
// there's an unfinished utterance
window.speechSynthesis.resume();
} else {
// start new utterance
const utterance = new SpeechSynthesisUtterance(utteranceWord);
this.synth1.speak(utterance);
};
this.synth1 = window.speechSynthesis;
this.sayWord = () => {
if (window.speechSynthesis.speaking) {
// there's an unfinished utterance
window.speechSynthesis.resume();
} else {
// start new utterance
const utterance = new SpeechSynthesisUtterance(utteranceWord);
// set utterance to global
utterance.voice = voice
this.synth1.speak(utterance);
};

let boxSpitter = "<button class='boxTemplate " + bgColor +"'id='box-" + boxNumber + "'><p>" + utteranceWord.toUpperCase() + "</p><img src='../img/" + imgSrc + "' alt='"+ altText +"'></button>";
document.getElementById('mainContainer').insertAdjacentHTML("beforeend", boxSpitter);
// "<button id='box-" + boxNumber + "'></button>";

let box = document.querySelector("#box-" + boxNumber);
box.addEventListener("click", this.sayWord.bind(this));

}
};

let boxSpitter = "<button class='boxTemplate " + bgColor + "'id='box-" + boxNumber + "'><p>" + utteranceWord.toUpperCase() + "</p><img src='../img/" + imgSrc + "' alt='" + altText + "'></button>";
document.getElementById('mainContainer').insertAdjacentHTML("beforeend", boxSpitter);
// "<button id='box-" + boxNumber + "'></button>";

for (let i = 0; i < dataList.length; i++) {
let x = dataList[i].title
x = new MakeNewUtterance(dataList[i].id + 1, dataList[i].title, dataList[i].imageSrc, dataList[i].cssClass, dataList[i].imageAlt);
let box = document.querySelector("#box-" + boxNumber);
box.addEventListener("click", this.sayWord.bind(this));

}


for (let i = 0; i < dataList.length; i++) {
let x = dataList[i].title
x = new MakeNewUtterance(dataList[i].id + 1, dataList[i].title, dataList[i].imageSrc, dataList[i].cssClass, dataList[i].imageAlt);
}

const synth = window.speechSynthesis;

// Code for click event to add tiles. Just a test

// document.querySelector('#addBtn').addEventListener('click', () => {
// let insertWord = document.querySelector("#keyboard").value;
// new MakeNewUtterance(insertWord, insertWord, 'plastic_bag.svg', 'darkGreen')
// })

document.querySelector("#submitText").addEventListener("click", run)

document.querySelector('#keyboard').addEventListener('keydown', e => {
if (e.keyCode == 13) {
e.preventDefault()
return run()
}

const synth = window.speechSynthesis;

// Code for click event to add tiles. Just a test

// document.querySelector('#addBtn').addEventListener('click', () => {
// let insertWord = document.querySelector("#keyboard").value;
// new MakeNewUtterance(insertWord, insertWord, 'plastic_bag.svg', 'darkGreen')
// })

document.querySelector("#submitText").addEventListener("click", run)

document.querySelector('#keyboard').addEventListener('keydown', e => {
if (e.keyCode == 13) {
e.preventDefault()
return run()
}
});

function run() {

const typeToTalk = document.querySelector("#keyboard").value;
});

function run() {

const typeToTalk = document.querySelector("#keyboard").value;
const yellText = `${typeToTalk}`;

document.querySelector("#keyboard").innerText = yellText;

// set yellThis to the global
let yellThis = new SpeechSynthesisUtterance(yellText);
yellThis.voice = voice

synth.speak(yellThis);
}
}