-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio-test.html
More file actions
271 lines (232 loc) · 9.35 KB
/
audio-test.html
File metadata and controls
271 lines (232 loc) · 9.35 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Audio Recording Test - Safari Compatibility</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
button {
background: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #0056b3;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
.status {
margin: 10px 0;
padding: 10px;
border-radius: 4px;
}
.success { background: #d4edda; color: #155724; }
.error { background: #f8d7da; color: #721c24; }
.info { background: #d1ecf1; color: #0c5460; }
#log {
background: #f8f9fa;
border: 1px solid #dee2e6;
padding: 10px;
border-radius: 4px;
max-height: 300px;
overflow-y: auto;
font-family: monospace;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<h1>Audio Recording Test</h1>
<p>This page tests audio recording compatibility across different browsers, especially Safari.</p>
<div>
<button id="testFormats">Test Audio Formats</button>
<button id="startRecord">Start Recording</button>
<button id="stopRecord" disabled>Stop Recording</button>
</div>
<div id="status" class="status info">Ready to test</div>
<div>
<h3>Console Log:</h3>
<div id="log"></div>
</div>
</div>
<script>
// Audio utilities (same as in audioUtils.ts)
function getSupportedMimeType() {
const types = [
'audio/webm;codecs=opus',
'audio/webm',
'audio/mp4',
'audio/ogg;codecs=opus',
'audio/wav',
'audio/aac',
'audio/mpeg'
]
for (const type of types) {
if (MediaRecorder.isTypeSupported(type)) {
log(`Supported audio format: ${type}`)
return type
}
}
log('No supported audio format found', 'error')
return null
}
function createMediaRecorder(stream) {
const mimeType = getSupportedMimeType()
if (mimeType) {
return new MediaRecorder(stream, { mimeType })
} else {
return new MediaRecorder(stream)
}
}
function getAudioBlobType() {
const mimeType = getSupportedMimeType()
if (mimeType) {
return mimeType.split(';')[0]
}
return 'audio/webm'
}
function getBrowserInfo() {
const userAgent = navigator.userAgent
const isSafari = userAgent.toLowerCase().includes('safari') && !userAgent.toLowerCase().includes('chrome')
const isIOS = /iPad|iPhone|iPod/.test(userAgent)
let browserName = 'Unknown'
let browserVersion = 'Unknown'
if (isSafari) {
browserName = 'Safari'
const match = userAgent.match(/Version\/(\d+\.\d+)/)
browserVersion = match ? match[1] : 'Unknown'
} else if (userAgent.includes('Chrome')) {
browserName = 'Chrome'
const match = userAgent.match(/Chrome\/(\d+\.\d+)/)
browserVersion = match ? match[1] : 'Unknown'
} else if (userAgent.includes('Firefox')) {
browserName = 'Firefox'
const match = userAgent.match(/Firefox\/(\d+\.\d+)/)
browserVersion = match ? match[1] : 'Unknown'
} else if (userAgent.includes('Edge')) {
browserName = 'Edge'
const match = userAgent.match(/Edge\/(\d+\.\d+)/)
browserVersion = match ? match[1] : 'Unknown'
}
return {
name: browserName,
version: browserVersion,
isSafari,
isIOS
}
}
function testAudioFormats() {
log('=== Audio Format Support Test ===')
const browserInfo = getBrowserInfo()
log(`Browser: ${browserInfo.name} ${browserInfo.version}`)
log(`Is Safari: ${browserInfo.isSafari}`)
log(`Is iOS: ${browserInfo.isIOS}`)
const types = [
'audio/webm;codecs=opus',
'audio/webm',
'audio/mp4',
'audio/ogg;codecs=opus',
'audio/wav',
'audio/aac',
'audio/mpeg'
]
log('Supported formats:')
types.forEach(type => {
const supported = MediaRecorder.isTypeSupported(type)
log(`${type}: ${supported ? '✅' : '❌'}`)
})
const supportedType = getSupportedMimeType()
log(`Selected format: ${supportedType || 'None'}`)
log('=== End Test ===')
}
function log(message, type = 'info') {
const logDiv = document.getElementById('log')
const timestamp = new Date().toLocaleTimeString()
const logEntry = document.createElement('div')
logEntry.textContent = `[${timestamp}] ${message}`
logEntry.className = type
logDiv.appendChild(logEntry)
logDiv.scrollTop = logDiv.scrollHeight
console.log(message)
}
function updateStatus(message, type = 'info') {
const statusDiv = document.getElementById('status')
statusDiv.textContent = message
statusDiv.className = `status ${type}`
}
let mediaRecorder = null
let audioChunks = []
document.getElementById('testFormats').addEventListener('click', () => {
testAudioFormats()
updateStatus('Audio format test completed. Check console log above.', 'success')
})
document.getElementById('startRecord').addEventListener('click', async () => {
try {
updateStatus('Requesting microphone access...', 'info')
testAudioFormats()
const browserInfo = getBrowserInfo()
log(`Browser info: ${JSON.stringify(browserInfo)}`)
const stream = await navigator.mediaDevices.getUserMedia({ audio: true })
mediaRecorder = createMediaRecorder(stream)
audioChunks = []
mediaRecorder.ondataavailable = (event) => {
if (event.data.size > 0) {
audioChunks.push(event.data)
log(`Audio chunk received: ${event.data.size} bytes`)
}
}
mediaRecorder.onstop = () => {
log('Recording stopped')
const audioBlob = new Blob(audioChunks, { type: getAudioBlobType() })
log(`Audio blob created: ${audioBlob.size} bytes, type: ${audioBlob.type}`)
// Create audio element to test playback
const audioUrl = URL.createObjectURL(audioBlob)
const audio = new Audio(audioUrl)
audio.controls = true
document.body.appendChild(audio)
updateStatus(`Recording completed! Audio size: ${audioBlob.size} bytes`, 'success')
stream.getTracks().forEach(track => track.stop())
}
mediaRecorder.start()
log('Recording started...')
updateStatus('Recording... Click "Stop Recording" to finish', 'info')
document.getElementById('startRecord').disabled = true
document.getElementById('stopRecord').disabled = false
} catch (error) {
log(`Error: ${error.message}`, 'error')
updateStatus(`Error: ${error.message}`, 'error')
}
})
document.getElementById('stopRecord').addEventListener('click', () => {
if (mediaRecorder && mediaRecorder.state === 'recording') {
mediaRecorder.stop()
document.getElementById('startRecord').disabled = false
document.getElementById('stopRecord').disabled = true
}
})
// Initial test
testAudioFormats()
updateStatus('Page loaded. Click "Test Audio Formats" to see detailed support information.', 'info')
</script>
</body>
</html>