AiDeveloper1 commited on
Commit
a584900
·
verified ·
1 Parent(s): 016c4c9

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +92 -70
index.html CHANGED
@@ -1,82 +1,104 @@
1
  <!DOCTYPE html>
2
- <html lang="en">
3
  <head>
4
- <meta charset="UTF-8">
5
- <title>Voice Command | Chatbot</title>
6
- <style>
7
- .chat-container {
8
- max-width: 400px;
9
- margin: 20px auto;
10
- padding: 10px;
11
- border: 1px solid #ccc;
12
- border-radius: 5px;
13
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
14
- font-family: Arial, sans-serif;
15
- }
16
- .user-message {
17
- background-color: #f0f0f0;
18
- border-radius: 5px;
19
- padding: 5px 10px;
20
- margin: 5px 0;
21
- text-align: right;
22
- }
23
- .bot-message {
24
- background-color: #d3e9ff;
25
- border-radius: 5px;
26
- padding: 5px 10px;
27
- margin: 5px 0;
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
- <!-- Language Selection -->
43
- <select id="languageSelector">
44
- <option value="en-US">English (US)</option>
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
- <div class="speaker" style="display: flex; justify-content: space-between; width: 100%; box-shadow: 0 0 13px #0000003d; border-radius: 5px; margin-top: 10px;">
54
- <p id="action" style="color: grey; font-weight: 800; padding: 0; padding-left: 2rem;"></p>
55
- <button id="speech" onclick="runSpeechRecog()" style="border: transparent; padding: 0 0.5rem;">
56
- Tap to Speak
57
- </button>
58
- </div>
59
- </div>
60
 
61
- <button onclick="speak()">Speak</button>
62
- <script>
63
- function speak() {
64
  const synth = window.speechSynthesis;
65
- const utter = new SpeechSynthesisUtterance("Bonjour, comment ça va ?");
66
- utter.lang = 'fr-FR';
 
 
 
 
 
 
 
 
67
 
 
 
 
 
 
 
 
 
 
 
 
68
 
 
 
 
 
 
 
69
 
70
- // Wait for voices to be loaded (Safari quirk)
71
- const interval = setInterval(() => {
72
- const voices = synth.getVoices();
73
- if (voices.length > 0) {
74
- utter.voice = voices.find(v => v.lang === 'en-US') || voices[0];
75
- synth.speak(utter);
76
- clearInterval(interval);
77
- }
78
- }, 100);
79
- }
80
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>