|
5 | 5 | <div v-if="mode==='audioImageRecord'" class="mb-3"> |
6 | 6 | <img class="img-fluid" :src="fieldData['http://schema.org/image'][0]['@id']" /> |
7 | 7 | </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> |
8 | 15 | <div v-if="mode==='audioRecordNumberTask'" class="mb-3"> |
9 | 16 | <strong style="font-size:30px">{{ generateNumber }}</strong> |
10 | 17 | </div> |
|
27 | 34 | <span> {{ $t('play-button') }} </span> |
28 | 35 | </b-button> |
29 | 36 |
|
| 37 | + |
30 | 38 | <b-button variant="secondary" |
31 | 39 | v-if="hasRecording && isPlaying" @click="pause" ref="play"> |
32 | 40 | <span> {{ $t('pause-button') }} </span> |
33 | 41 | </b-button> |
34 | 42 |
|
| 43 | + |
35 | 44 | <div v-if="hasRecording" class="mt-2"> |
36 | 45 | <a href="" @click="reset">{{ $t('redo-recording') }}</a> |
37 | 46 | </div> |
38 | 47 | </div> |
39 | 48 | </div> |
40 | 49 | </template> |
41 | 50 |
|
| 51 | + |
42 | 52 | <style> |
43 | 53 | </style> |
44 | 54 |
|
| 55 | + |
45 | 56 | <script> |
46 | 57 | import _ from 'lodash'; |
47 | 58 |
|
| 59 | +
|
48 | 60 | const MediaStreamRecorder = require('msr'); |
49 | 61 |
|
| 62 | +
|
50 | 63 | export default { |
51 | 64 | name: 'audioRecord', |
52 | 65 | props: { |
|
70 | 83 | isRecording: false, |
71 | 84 | hasRecording: false, |
72 | 85 | audioCtx: {}, |
73 | | - audioConstraints: { audio: true, video: false }, |
| 86 | + audioConstraints: { |
| 87 | + audio: { |
| 88 | + deviceId:{exact:this.audioStreamDevice}, |
| 89 | + }, |
| 90 | + video: false }, |
74 | 91 | // chunks: [], |
75 | 92 | mediaRecorder: {}, |
76 | 93 | supported: null, |
77 | 94 | interval: {}, |
78 | 95 | timeRemaining: null, |
79 | 96 | isPlaying: false, |
| 97 | + devices: null, |
| 98 | + tempDeviceName: null, |
80 | 99 | }; |
81 | 100 | }, |
82 | 101 | 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 | + }, |
83 | 119 | record() { |
| 120 | + if (!this.audioStreamDevice){ |
| 121 | + this.setDevice(); |
| 122 | + } |
84 | 123 | this.isRecording = true; |
85 | 124 | this.mediaRecorder.start(this.recordingTime); |
86 | 125 | this.interval = setInterval(this.countdown, 1000); |
|
133 | 172 | }, |
134 | 173 | }, |
135 | 174 | computed: { |
| 175 | + audioStreamDevice(){ |
| 176 | + return this.$store.state.selectedAudioInput; |
| 177 | + }, |
136 | 178 | recordingTime() { |
137 | 179 | return this.constraints['http://schema.org/maxValue'][0]['@value']; |
138 | 180 | }, |
|
151 | 193 | this.recording.onended = this.endPlay; |
152 | 194 | const AudioContext = window.AudioContext || window.webkitAudioContext; |
153 | 195 | this.audioCtx = new AudioContext(); |
| 196 | + this.getDevices() |
154 | 197 | if (navigator.mediaDevices.getUserMedia) { |
155 | 198 | this.supported = true; |
156 | 199 | navigator.mediaDevices.getUserMedia(this.audioConstraints).then(this.initialize, this.error); |
|
182 | 225 | if (this.init === 'skip' || this.init === 'dontKnow') { |
183 | 226 | this.hasRecording = false; |
184 | 227 | } |
185 | | - }, |
| 228 | + } |
186 | 229 | }, |
187 | 230 | }; |
188 | 231 | </script> |
0 commit comments