Spaces:
Running
Running
Update index.html
Browse files- index.html +92 -70
index.html
CHANGED
@@ -1,82 +1,104 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html lang="
|
3 |
<head>
|
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 |
-
#languageSelector {
|
30 |
-
width: 100%;
|
31 |
-
margin-top: 10px;
|
32 |
-
padding: 5px;
|
33 |
-
border-radius: 5px;
|
34 |
-
border: 1px solid #ccc;
|
35 |
-
}
|
36 |
-
</style>
|
37 |
</head>
|
38 |
<body>
|
39 |
-
<div class="chat-container">
|
40 |
-
<div id="chat-box"></div>
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
<option value="hi-IN">Hindi (India)</option>
|
46 |
-
<option value="es-ES">Spanish (Spain)</option>
|
47 |
-
<option value="fr-FR">French (France)</option>
|
48 |
-
<option value="de-DE">German (Germany)</option>
|
49 |
-
<option value="ar-SA">Arabic (Saudi Arabia)</option>
|
50 |
-
<!-- Add more as needed -->
|
51 |
-
</select>
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
</button>
|
58 |
-
</div>
|
59 |
-
</div>
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
function speak() {
|
64 |
const synth = window.speechSynthesis;
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
</body>
|
82 |
-
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html lang="ja">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>Japanese Voice Agent</title>
|
6 |
+
<style>
|
7 |
+
#action, #status {
|
8 |
+
text-align: center;
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
margin: 10px;
|
11 |
+
}
|
12 |
+
#speech {
|
13 |
+
display: block;
|
14 |
+
margin: 20px auto;
|
15 |
+
padding: 10px 20px;
|
16 |
+
font-size: 18px;
|
17 |
+
font-weight: bold;
|
18 |
+
background: #007bff;
|
19 |
+
color: white;
|
20 |
+
border: none;
|
21 |
+
border-radius: 5px;
|
22 |
+
cursor: pointer;
|
23 |
+
}
|
24 |
+
#speech:hover {
|
25 |
+
background: #0056b3;
|
26 |
+
}
|
27 |
+
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
</head>
|
29 |
<body>
|
|
|
|
|
30 |
|
31 |
+
<p id="action">タップして話す</p>
|
32 |
+
<button id="speech">Tap to Speak</button>
|
33 |
+
<p id="status"></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
<script>
|
36 |
+
const action = document.getElementById('action');
|
37 |
+
const status = document.getElementById('status');
|
38 |
+
const speechButton = document.getElementById('speech');
|
|
|
|
|
|
|
39 |
|
40 |
+
// Load Japanese voice
|
41 |
+
let voices = [];
|
|
|
42 |
const synth = window.speechSynthesis;
|
43 |
+
function loadVoices() {
|
44 |
+
return new Promise(resolve => {
|
45 |
+
voices = synth.getVoices();
|
46 |
+
if (voices.length > 0) resolve();
|
47 |
+
else synth.addEventListener('voiceschanged', () => {
|
48 |
+
voices = synth.getVoices();
|
49 |
+
resolve();
|
50 |
+
});
|
51 |
+
});
|
52 |
+
}
|
53 |
|
54 |
+
async function speakText(text) {
|
55 |
+
await loadVoices();
|
56 |
+
const utter = new SpeechSynthesisUtterance(text);
|
57 |
+
const japaneseVoice = voices.find(v => v.lang === 'ja-JP');
|
58 |
+
if (japaneseVoice) {
|
59 |
+
utter.voice = japaneseVoice;
|
60 |
+
utter.lang = 'ja-JP';
|
61 |
+
}
|
62 |
+
synth.cancel(); // Cancel any ongoing speech
|
63 |
+
synth.speak(utter);
|
64 |
+
}
|
65 |
|
66 |
+
function runSpeechRecognition() {
|
67 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
68 |
+
if (!SpeechRecognition) {
|
69 |
+
status.textContent = 'このブラウザは音声認識をサポートしていません。';
|
70 |
+
return;
|
71 |
+
}
|
72 |
|
73 |
+
const recognition = new SpeechRecognition();
|
74 |
+
recognition.lang = 'ja-JP';
|
75 |
+
recognition.interimResults = false;
|
76 |
+
|
77 |
+
recognition.onstart = () => {
|
78 |
+
action.textContent = '聞いています...';
|
79 |
+
status.textContent = '';
|
80 |
+
};
|
81 |
+
|
82 |
+
recognition.onresult = (event) => {
|
83 |
+
const transcript = event.results[0][0].transcript;
|
84 |
+
action.textContent = '認識完了';
|
85 |
+
status.textContent = `聞き取った内容: ${transcript}`;
|
86 |
+
speakText(transcript); // Speak back the text
|
87 |
+
};
|
88 |
+
|
89 |
+
recognition.onerror = (event) => {
|
90 |
+
action.textContent = 'エラー';
|
91 |
+
status.textContent = `認識エラー: ${event.error}`;
|
92 |
+
};
|
93 |
+
|
94 |
+
recognition.onend = () => {
|
95 |
+
action.textContent = 'タップして話す';
|
96 |
+
};
|
97 |
+
|
98 |
+
recognition.start();
|
99 |
+
}
|
100 |
+
|
101 |
+
speechButton.addEventListener('click', runSpeechRecognition);
|
102 |
+
</script>
|
103 |
</body>
|
104 |
+
</html>
|