Skip to content

Commit 2f29ed1

Browse files
committed
Lets user choose the right type of audio input (attempt #1)
1 parent c03c21d commit 2f29ed1

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

src/components/InputSelector/InputSelector.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ export default {
308308
ipAddress: {
309309
type: String,
310310
},
311+
311312
},
312313
components: {
313314
ParticipantId,
@@ -328,12 +329,12 @@ export default {
328329
TimeRange,
329330
SelectInput,
330331
StaticReadOnly,
332+
//InputSelector-AudioRecord: AudioRecord
331333
// Static,
332334
},
333335
data() {
334336
return {
335-
336-
};
337+
}
337338
},
338339
methods: {
339340
skip() {

src/components/Inputs/WebAudioRecord/Audio.vue

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
<div v-if="mode==='audioImageRecord'" class="mb-3">
66
<img class="img-fluid" :src="fieldData['http://schema.org/image'][0]['@id']" />
77
</div>
8+
<!--Added by Veronika - trying to open a select menu if audio input type not indicated-->
9+
<div v-if="(!audioStreamDevice)" onload="getDevices">
10+
<label>Please select the type of microphone you wish to use.</label>
11+
<select @change="nameDevice">
12+
<option v-for="device in devices" :key="device" :value="device">{{ device }}</option>
13+
</select>
14+
</div>
815
<div v-if="mode==='audioRecordNumberTask'" class="mb-3">
916
<strong style="font-size:30px">{{ generateNumber }}</strong>
1017
</div>
@@ -27,26 +34,32 @@
2734
<span> {{ $t('play-button') }} </span>
2835
</b-button>
2936

37+
3038
<b-button variant="secondary"
3139
v-if="hasRecording && isPlaying" @click="pause" ref="play">
3240
<span> {{ $t('pause-button') }} </span>
3341
</b-button>
3442

43+
3544
<div v-if="hasRecording" class="mt-2">
3645
<a href="" @click="reset">{{ $t('redo-recording') }}</a>
3746
</div>
3847
</div>
3948
</div>
4049
</template>
4150

51+
4252
<style>
4353
</style>
4454

55+
4556
<script>
4657
import _ from 'lodash';
4758
59+
4860
const MediaStreamRecorder = require('msr');
4961
62+
5063
export default {
5164
name: 'audioRecord',
5265
props: {
@@ -70,17 +83,43 @@
7083
isRecording: false,
7184
hasRecording: false,
7285
audioCtx: {},
73-
audioConstraints: { audio: true, video: false },
86+
audioConstraints: {
87+
audio: {
88+
deviceId:{exact:this.audioStreamDevice},
89+
},
90+
video: false },
7491
// chunks: [],
7592
mediaRecorder: {},
7693
supported: null,
7794
interval: {},
7895
timeRemaining: null,
7996
isPlaying: false,
97+
devices: null,
98+
tempDeviceName: null,
8099
};
81100
},
82101
methods: {
102+
getDevices() {
103+
navigator.mediaDevices.enumerateDevices().then((devices) => {
104+
const audioInputDevices = devices.filter((device) => device.kind === 'audioinput');
105+
this.devices = audioInputDevices.map((device) => device.label || `Microphone ${device.deviceId}`);
106+
}).catch((err) => {
107+
console.error("Error enumerating devices:", err);
108+
});
109+
},
110+
selectAudioDevice(deviceId){
111+
this.audioStreamDevice = deviceId;
112+
},
113+
nameDevice(e){
114+
this.tempDeviceName = e.target.value
115+
},
116+
setDevice(){
117+
this.$store.state.selectedAudioInput = this.tempDeviceName;
118+
},
83119
record() {
120+
if (!this.audioStreamDevice){
121+
this.setDevice();
122+
}
84123
this.isRecording = true;
85124
this.mediaRecorder.start(this.recordingTime);
86125
this.interval = setInterval(this.countdown, 1000);
@@ -133,6 +172,9 @@
133172
},
134173
},
135174
computed: {
175+
audioStreamDevice(){
176+
return this.$store.state.selectedAudioInput;
177+
},
136178
recordingTime() {
137179
return this.constraints['http://schema.org/maxValue'][0]['@value'];
138180
},
@@ -151,6 +193,7 @@
151193
this.recording.onended = this.endPlay;
152194
const AudioContext = window.AudioContext || window.webkitAudioContext;
153195
this.audioCtx = new AudioContext();
196+
this.getDevices()
154197
if (navigator.mediaDevices.getUserMedia) {
155198
this.supported = true;
156199
navigator.mediaDevices.getUserMedia(this.audioConstraints).then(this.initialize, this.error);
@@ -182,7 +225,7 @@
182225
if (this.init === 'skip' || this.init === 'dontKnow') {
183226
this.hasRecording = false;
184227
}
185-
},
228+
}
186229
},
187230
};
188231
</script>

src/store/store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const state = {
2828
queryParams: {},
2929
token: null,
3030
landing: [],
31-
hasExport: false
31+
hasExport: false,
32+
selectedAudioInput: null
3233
};
3334

3435
const getters = {

0 commit comments

Comments
 (0)