-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
94 lines (82 loc) · 3.24 KB
/
Copy pathindex.html
File metadata and controls
94 lines (82 loc) · 3.24 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="../../favicon.svg" type="image/svg+xml">
<title>ResponsiveVoice - Basic Example</title>
<link rel="stylesheet" href="../shared/demo-base.css">
<link rel="stylesheet" href="./styles.css">
<link rel="stylesheet" href="../shared/api-key-scaffold.css">
<script src="../shared/api-key-scaffold.js"></script>
</head>
<body>
<a href="../../" class="back-link">← Back to Examples</a>
<div class="header">
<img src="../../favicon.svg" class="logo" width="32" height="32" alt="ResponsiveVoice logo">
<h1>Basic Example</h1>
<span id="demoBadge" class="demo-badge" hidden>Demo Mode</span>
</div>
<p class="subtitle">The simplest way to add text-to-speech to your web page.</p>
<div class="form-group">
<label for="text">Text to speak:</label>
<textarea id="text" rows="3">Hello! This is a basic example of ResponsiveVoice text-to-speech.</textarea>
</div>
<button type="button" id="speakBtn" disabled>Speak</button>
<button type="button" id="cancelBtn" class="button-secondary" disabled>Cancel</button>
<div id="status">Initializing...</div>
<!-- Load ResponsiveVoice from CDN -->
<script src="https://cdn.responsivevoice.org/sdk/latest/responsivevoice.js"></script>
<script>
// The IIFE auto-creates window.responsiveVoice as an instance
const rv = window.responsiveVoice;
const textInput = document.getElementById('text');
const speakBtn = document.getElementById('speakBtn');
const cancelBtn = document.getElementById('cancelBtn');
const status = document.getElementById('status');
const demoBadge = document.getElementById('demoBadge');
rv.addEventListener('OnReady', () => {
status.textContent = 'Ready! Click "Speak" to hear the text.';
speakBtn.disabled = false;
if (rv.isDemoMode()) demoBadge.hidden = false;
});
rv.addEventListener('OnStart', () => {
status.textContent = 'Speaking...';
speakBtn.disabled = true;
cancelBtn.disabled = false;
});
rv.addEventListener('OnEnd', () => {
status.textContent = 'Finished speaking.';
speakBtn.disabled = false;
cancelBtn.disabled = true;
});
rv.addEventListener('OnError', (e) => {
status.textContent = `Error: ${e.error?.message || 'Unknown error'}`;
speakBtn.disabled = false;
cancelBtn.disabled = true;
});
// Initialize ResponsiveVoice.
// Without an API key the library runs in demo mode (browser-native voices only);
// the "Demo Mode" badge in the header above indicates this state.
rv.init({
// Get a free API key at https://responsivevoice.org/register
// apiKey: 'YOUR_RESPONSIVEVOICE_API_KEY',
}).catch(err => {
status.textContent = `Failed to initialize: ${err.message}`;
});
// Button handlers
speakBtn.addEventListener('click', () => {
const text = textInput.value.trim();
if (text) {
rv.speak(text);
}
});
cancelBtn.addEventListener('click', () => {
rv.cancel();
status.textContent = 'Cancelled.';
speakBtn.disabled = false;
cancelBtn.disabled = true;
});
</script>
</body>
</html>