-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.html
120 lines (97 loc) · 3 KB
/
testing.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text-to-Speech with Accordion Menus</title>
<style>
.accordion {
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
}
.accordion-header {
background-color: #f4f4f4;
padding: 10px;
cursor: pointer;
}
.accordion-content {
display: none;
padding: 10px;
}
</style>
</head>
<body>
<div id="accordionContainer">
<!-- Accordions will be dynamically added here -->
</div>
<button onclick="speak()">Speak</button>
<audio id="audio" controls>
Your browser does not support the audio element.
</audio>
<script>
// Sample data fetched from the .tsv file
const data = [
{ stretch: 'Stretch1', switch: 'Switch1', time: '10s', reps: 5, group: 'warmup, upper body' },
{ stretch: 'Stretch2', switch: 'Switch2', time: '15s', reps: 8, group: 'warmup, middle body' },
{ stretch: 'Stretch3', switch: 'Switch3', time: '20s', reps: 10, group: 'warmup, lower body' }
];
// Function to create accordion menus based on the fetched data
function createAccordions() {
const accordionContainer = document.getElementById('accordionContainer');
// Group accordion mapping
const groupAccordions = {};
data.forEach(item => {
const groupName = item.group;
// Create accordion for the group if not created yet
if (!groupAccordions[groupName]) {
const accordion = document.createElement('div');
accordion.className = 'accordion';
const header = document.createElement('div');
header.className = 'accordion-header';
header.textContent = groupName;
header.onclick = function() {
toggleAccordion(this);
};
const content = document.createElement('div');
content.className = 'accordion-content';
accordion.appendChild(header);
accordion.appendChild(content);
groupAccordions[groupName] = {
accordion: accordion,
content: content
};
accordionContainer.appendChild(accordion);
}
// Create stretch item
const stretchItem = document.createElement('div');
stretchItem.textContent = item.stretch;
groupAccordions[groupName].content.appendChild(stretchItem);
});
}
// Function to toggle accordion content
function toggleAccordion(header) {
const content = header.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
}
// Function to read checked items
function speak() {
const textList = document.querySelectorAll("#accordionContainer .accordion-content div");
let ssml = '<speak>';
textList.forEach(item => {
const text = item.textContent.trim();
ssml += text + ' ';
});
ssml += '</speak>';
// Fetch and process the ssml as before...
console.log(ssml);
}
// Call the function to create accordions when the page loads
window.onload = createAccordions;
</script>
</body>
</html>