dotenv if exists;
auto create rec folder; select audio device on client;
This commit is contained in:
@ -18,6 +18,10 @@
|
||||
id="autosend" />
|
||||
<span class="slider">Continious</span>
|
||||
</label>
|
||||
<select id="input-devices">
|
||||
<option value="default">Default</option>
|
||||
</select>
|
||||
|
||||
<button id="record-button"
|
||||
disabled>Start Recording</button>
|
||||
<span id="connection-status"></span>
|
||||
@ -29,6 +33,7 @@
|
||||
width="500"
|
||||
height="500"></canvas>
|
||||
<script>
|
||||
let selectedDeviceId = "default";
|
||||
let socket;
|
||||
let audioRecorder;
|
||||
let recording = false;
|
||||
@ -93,7 +98,7 @@
|
||||
|
||||
// count speaking and silence
|
||||
if (averageVolume > threshold) {
|
||||
if (speakingCount == 0 && audioRecorder) {
|
||||
if (autosend.checked && speakingCount == 0 && audioRecorder) {
|
||||
console.log("startint new recording");
|
||||
audioRecorder.stop();
|
||||
audioRecorder.start();
|
||||
@ -249,6 +254,57 @@
|
||||
}
|
||||
}
|
||||
|
||||
function enumerateDevices() {
|
||||
// Enumerate the available audio input devices
|
||||
navigator.mediaDevices.enumerateDevices()
|
||||
.then(function (devices) {
|
||||
var audioInputDevices = devices.filter(function (device) {
|
||||
return device.kind === 'audioinput';
|
||||
});
|
||||
console.log(audioInputDevices.length + ' audio input devices found');
|
||||
|
||||
// If more than one audio input device is available, populate the select list
|
||||
if (audioInputDevices.length > 1) {
|
||||
audioInputDevices.forEach(function (device) {
|
||||
var option = document.createElement('option');
|
||||
option.value = device.deviceId;
|
||||
option.text = device.label || 'Device ' + device.deviceId;
|
||||
inputDevices.appendChild(option);
|
||||
});
|
||||
// Listen for changes to the select list and connect to the selected audio input device
|
||||
inputDevices.addEventListener('change', function (event) {
|
||||
var selectedDeviceId = event.target.value;
|
||||
var constraints = { audio: { deviceId: selectedDeviceId } };
|
||||
navigator.mediaDevices.getUserMedia(constraints)
|
||||
.then(function (stream) {
|
||||
// Handle the audio stream from the selected device here
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('Error accessing audio stream:', error);
|
||||
});
|
||||
});
|
||||
}
|
||||
// If only one audio input device is available, connect to it automatically
|
||||
else if (audioInputDevices.length === 1) {
|
||||
var constraints = { audio: { deviceId: audioInputDevices[0].deviceId } };
|
||||
navigator.mediaDevices.getUserMedia(constraints)
|
||||
.then(function (stream) {
|
||||
// Handle the audio stream from the selected device here
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('Error accessing audio stream:', error);
|
||||
});
|
||||
}
|
||||
// If no audio input devices are available, show an error message
|
||||
else {
|
||||
console.log('No audio input devices available');
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('Error listing audio input devices:', error);
|
||||
});
|
||||
}
|
||||
|
||||
window.onload = () => {
|
||||
recordButton = document.getElementById("record-button");
|
||||
recordButton.addEventListener("click", toggleListening);
|
||||
@ -256,9 +312,8 @@
|
||||
//transcription = document.getElementById("transcription");
|
||||
//autosend = document.getElementById("autosend");
|
||||
statusRecording = document.getElementById("status-recording");
|
||||
|
||||
|
||||
|
||||
|
||||
enumerateDevices();
|
||||
connect(socket);
|
||||
};
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user