|
159 | 159 |
|
160 | 160 | <div
|
161 | 161 | class="vac-svg-button vac-icon-audio-confirm"
|
162 |
| - @click="toggleRecorder" |
| 162 | + @click="toggleRecorder(false)" |
163 | 163 | >
|
164 | 164 | <slot name="audio-stop-icon">
|
165 | 165 | <svg-icon name="checkmark" />
|
166 | 166 | </slot>
|
167 | 167 | </div>
|
168 | 168 | </template>
|
169 | 169 |
|
170 |
| - <div v-else class="vac-svg-button" @click="toggleRecorder"> |
| 170 | + <div v-else class="vac-svg-button" @click="toggleRecorder(true)"> |
171 | 171 | <slot name="microphone-icon">
|
172 | 172 | <svg-icon name="microphone" class="vac-icon-microphone" />
|
173 | 173 | </slot>
|
@@ -853,34 +853,42 @@ export default {
|
853 | 853 | format: this.format
|
854 | 854 | })
|
855 | 855 | },
|
856 |
| - toggleRecorder() { |
857 |
| - this.isRecording = !this.isRecording |
| 856 | + toggleRecorder(recording) { |
| 857 | + this.isRecording = recording |
858 | 858 |
|
859 | 859 | if (!this.recorder.isRecording) {
|
860 | 860 | setTimeout(() => this.recorder.start(), 200)
|
861 | 861 | } else {
|
862 |
| - this.recorder.stop() |
863 |
| -
|
864 |
| - const record = this.recorder.records[0] |
865 |
| -
|
866 |
| - this.file = { |
867 |
| - blob: record.blob, |
868 |
| - name: `audio.${this.format}`, |
869 |
| - size: record.blob.size, |
870 |
| - duration: record.duration, |
871 |
| - type: record.blob.type, |
872 |
| - audio: true, |
873 |
| - localUrl: URL.createObjectURL(record.blob) |
874 |
| - } |
| 862 | + try { |
| 863 | + this.recorder.stop() |
| 864 | +
|
| 865 | + const record = this.recorder.records[0] |
| 866 | +
|
| 867 | + this.file = { |
| 868 | + blob: record.blob, |
| 869 | + name: `audio.${this.format}`, |
| 870 | + size: record.blob.size, |
| 871 | + duration: record.duration, |
| 872 | + type: record.blob.type, |
| 873 | + audio: true, |
| 874 | + localUrl: URL.createObjectURL(record.blob) |
| 875 | + } |
875 | 876 |
|
876 |
| - this.recorder = this.initRecorder() |
877 |
| - this.sendMessage() |
| 877 | + this.recorder = this.initRecorder() |
| 878 | + this.sendMessage() |
| 879 | + } catch { |
| 880 | + setTimeout(() => this.stopRecorder(), 100) |
| 881 | + } |
878 | 882 | }
|
879 | 883 | },
|
880 | 884 | stopRecorder() {
|
881 | 885 | if (this.recorder.isRecording) {
|
882 |
| - this.recorder.stop() |
883 |
| - this.recorder = this.initRecorder() |
| 886 | + try { |
| 887 | + this.recorder.stop() |
| 888 | + this.recorder = this.initRecorder() |
| 889 | + } catch { |
| 890 | + setTimeout(() => this.stopRecorder(), 100) |
| 891 | + } |
884 | 892 | }
|
885 | 893 | },
|
886 | 894 | openFile({ message, action }) {
|
|
0 commit comments