

240812 정다정 단어장 스피킹 녹음 기능 추가
@e47769b90c7ad4f0b34f38bb2a56a8a69a894941
--- client/views/pages/main/Chapter/Chapter2_1.vue
+++ client/views/pages/main/Chapter/Chapter2_1.vue
... | ... | @@ -1,63 +1,169 @@ |
1 | 1 |
<template> |
2 |
- <div id="Chapter1_1" class="content-wrap"> |
|
2 |
+ <div id="Chapter1_1" class="content-wrap"> |
|
3 | 3 |
<div class="title-box mb25 flex align-center mt40"> |
4 |
- <span class="title mr40">1. Hello WORLD</span> |
|
5 |
- <span class="subtitle">my name is dd</span> |
|
4 |
+ <span class="title mr40">1. Hello WORLD</span> |
|
5 |
+ <span class="subtitle">my name is dd</span> |
|
6 | 6 |
</div> |
7 | 7 |
<div class="flex justify-between align-center"> |
8 |
- <div class="pre-btn" @click="goToPage('Chapter2')"><img src="../../../../resources/img/left.png" alt=""></div> |
|
9 |
- <div class="content title-box"> |
|
10 |
- <p class="title mt25 title-bg">step2</p> |
|
11 |
- <div class="flex align-center mb30"> |
|
12 |
- <p class="subtitle2 mr20">오늘 배웠던 단어를 말하고 생성된 예문을 따라 읽어보세요</p> |
|
13 |
- <!-- <button><img src="../../../../resources/img/btn10_s.png" alt=""> |
|
14 |
- </button> --> |
|
15 |
- </div> |
|
16 |
- <div class="flex justify-center "> |
|
17 |
- <div class="readGroup"> |
|
18 |
- <section > |
|
19 |
- <div class="imgGroup flex justify-center"> |
|
20 |
- <div class="mic-btn"> |
|
21 |
- <img src="../../../../resources/img/btn11_s.png" alt=""> |
|
22 |
- </div> |
|
23 |
- |
|
24 |
- </div> |
|
25 |
- <article > |
|
26 |
- <input type="text" class="speak mb25" placeholder="오늘 배운 단어를 말해보세요!"> |
|
27 |
- <p class="read-ai"><img style="margin-top: -5px;" src="../../../../resources/img/img43_s.png" alt=""></p> |
|
28 |
- </article> |
|
29 |
- |
|
30 |
- </section> |
|
31 |
- |
|
8 |
+ <div class="pre-btn" @click="goToPage('Chapter2')"> |
|
9 |
+ <img src="../../../../resources/img/left.png" alt="" /> |
|
32 | 10 |
</div> |
33 |
- </div> |
|
34 |
- </div> |
|
35 |
- <div class="next-btn" @click="goToPage('Chapter2_2')"><img src="../../../../resources/img/right.png" alt=""></div> |
|
11 |
+ <div class="content title-box"> |
|
12 |
+ <p class="title mt25 title-bg">step2</p> |
|
13 |
+ <div class="flex align-center mb30"> |
|
14 |
+ <p class="subtitle2 mr20">오늘 배웠던 단어를 말하고 생성된 예문을 따라 읽어보세요</p> |
|
15 |
+ <!-- <button><img src="../../../../resources/img/btn10_s.png" alt=""> |
|
16 |
+ </button> --> |
|
17 |
+ </div> |
|
18 |
+ <div> |
|
19 |
+ <img src="http://localhost:8081/client/build/dad67b1726cb2d2b215965b433149ca3.png" data-num="1" /> |
|
20 |
+ <p> {{ word }} </p> |
|
21 |
+ <p> {{ mean }} </p> |
|
22 |
+ </div> |
|
23 |
+ <div class="flex justify-center"> |
|
24 |
+ <div class="readGroup"> |
|
25 |
+ <section> |
|
26 |
+ <div class="imgGroup flex justify-center"> |
|
27 |
+ <!-- 녹음 버튼 --> |
|
28 |
+ <div :class="['mic-btn', { notRecording: !isRecording }]" @click="toggleRecording"> |
|
29 |
+ <img src="../../../../resources/img/btn11_s.png" alt="" /> |
|
30 |
+ </div> |
|
31 |
+ </div> |
|
32 |
+ <article> |
|
33 |
+ <p class="speakText mb25"> |
|
34 |
+ <span v-if="transcription === null" |
|
35 |
+ >위의 버튼을 누른 후 오늘 배운 단어를 말해보세요!</span |
|
36 |
+ > |
|
37 |
+ <span v-else-if="!transcription || transcription.trim() === ''" |
|
38 |
+ >다시 말해보세요!</span |
|
39 |
+ > |
|
40 |
+ <span v-else>{{ transcription }}</span> |
|
41 |
+ </p> |
|
42 |
+ <p class="read-ai"> |
|
43 |
+ <img style="margin-top: -5px" src="../../../../resources/img/img43_s.png" alt="" /> |
|
44 |
+ </p> |
|
45 |
+ </article> |
|
46 |
+ </section> |
|
47 |
+ </div> |
|
48 |
+ </div> |
|
49 |
+ </div> |
|
50 |
+ <div class="next-btn" @click="goToPage('Chapter2_2')"> |
|
51 |
+ <img src="../../../../resources/img/right.png" alt="" /> |
|
52 |
+ </div> |
|
36 | 53 |
</div> |
37 |
- </div> |
|
38 |
- </template> |
|
39 |
- |
|
40 |
- <script> |
|
41 |
- export default { |
|
42 |
- data() { |
|
54 |
+ </div> |
|
55 |
+</template> |
|
56 |
+ |
|
57 |
+<script> |
|
58 |
+import axios from 'axios'; |
|
59 |
+import SvgIcon from '@jamescoyle/vue-icon'; |
|
60 |
+import { mdiStop } from '@mdi/js'; |
|
61 |
+export default { |
|
62 |
+ data() { |
|
43 | 63 |
return { |
44 |
- } |
|
45 |
- }, |
|
46 |
- methods: { |
|
64 |
+ isRecording: false, // 녹음 중 여부 |
|
65 |
+ mediaRecorder: null, |
|
66 |
+ audioChunks: [], // 녹음된 오디오 데이터 |
|
67 |
+ audioBlob: null, // 오디오 Blob 객체 |
|
68 |
+ transcription: null, // 서버에서 받아온 텍스트 결과 |
|
69 |
+ stream: null, // MediaStream 객체 |
|
70 |
+ |
|
71 |
+ path: mdiStop, |
|
72 |
+ |
|
73 |
+ /* audioURL : null // 오디오 URL 객체 */ |
|
74 |
+ |
|
75 |
+ word : "apple", |
|
76 |
+ mean : "사과", |
|
77 |
+ imageSrc : "http://localhost:8081/client/build/dad67b1726cb2d2b215965b433149ca3.png" |
|
78 |
+ }; |
|
79 |
+ }, |
|
80 |
+ methods: { |
|
47 | 81 |
goToPage(page) { |
48 |
- this.$router.push({ name: page }); |
|
49 |
- } |
|
50 |
- }, |
|
51 |
- watch: { |
|
52 |
- |
|
53 |
- }, |
|
54 |
- computed: { |
|
55 |
- |
|
56 |
- }, |
|
57 |
- components: { |
|
58 |
- }, |
|
59 |
- mounted() { |
|
60 |
- |
|
61 |
- } |
|
62 |
- } |
|
63 |
- </script>(No newline at end of file) |
|
82 |
+ this.$router.push({ name: page }); |
|
83 |
+ }, |
|
84 |
+ // 녹음 시작/중지 토글 |
|
85 |
+ async toggleRecording() { |
|
86 |
+ if (this.isRecording) { |
|
87 |
+ console.log('녹음 그만!'); |
|
88 |
+ this.stopRecording(); // 녹음 중이면 중지 |
|
89 |
+ } else { |
|
90 |
+ console.log('녹음 시작!'); |
|
91 |
+ await this.startRecording(); // 녹음 중이 아니면 녹음 시작 |
|
92 |
+ } |
|
93 |
+ }, |
|
94 |
+ |
|
95 |
+ // 녹음 시작 |
|
96 |
+ async startRecording() { |
|
97 |
+ this.audioChunks = []; // 오디오 초기화 |
|
98 |
+ this.stream = await navigator.mediaDevices.getUserMedia({ audio: true }); |
|
99 |
+ this.mediaRecorder = new MediaRecorder(this.stream); |
|
100 |
+ this.mediaRecorder.ondataavailable = (event) => { |
|
101 |
+ this.audioChunks.push(event.data); // 녹음 데이터 저장 |
|
102 |
+ }; |
|
103 |
+ this.mediaRecorder.onstop = () => { |
|
104 |
+ this.audioBlob = new Blob(this.audioChunks, { type: 'audio/wav' }); |
|
105 |
+ |
|
106 |
+ /******************************/ |
|
107 |
+ // this.audioURL = URL.createObjectURL(this.audioBlob); // 오디오 URL 생성 |
|
108 |
+ // console.log('Audio URL:', this.audioURL); |
|
109 |
+ /******************************/ |
|
110 |
+ |
|
111 |
+ console.log('Recorded Audio Blob:', this.audioBlob); // 콘솔에 Blob 확인 |
|
112 |
+ this.sendAudioToServer(); // 서버로 오디오 전송 |
|
113 |
+ }; |
|
114 |
+ this.mediaRecorder.start(); // 녹음 시작 |
|
115 |
+ this.isRecording = true; // 녹음 상태 변경 |
|
116 |
+ }, |
|
117 |
+ |
|
118 |
+ // 녹음 중지 |
|
119 |
+ stopRecording() { |
|
120 |
+ this.mediaRecorder.stop(); // 녹음 중단 |
|
121 |
+ |
|
122 |
+ if (this.stream) { |
|
123 |
+ this.stream.getTracks().forEach((track) => track.stop()); // 스트림의 모든 트랙 중지 |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ this.isRecording = false; // 녹음 상태 변경 |
|
127 |
+ }, |
|
128 |
+ |
|
129 |
+ // 오디오 전송 |
|
130 |
+ async sendAudioToServer() { |
|
131 |
+ const formData = new FormData(); |
|
132 |
+ formData.append('file', this.audioBlob, 'recording.wav'); |
|
133 |
+ try { |
|
134 |
+ const resposne = await axios.post('/api/speechToText.json', formData, { |
|
135 |
+ headers: { |
|
136 |
+ 'Content-Type': 'multipart/form-data', |
|
137 |
+ }, |
|
138 |
+ }); |
|
139 |
+ this.transcription = resposne.data; |
|
140 |
+ console.log(`받은 데이터 : ${this.transcription}`); |
|
141 |
+ } catch (error) { |
|
142 |
+ console.log('파일 전송 실패 : ', error); |
|
143 |
+ } |
|
144 |
+ }, |
|
145 |
+ }, |
|
146 |
+ watch: {}, |
|
147 |
+ computed: {}, |
|
148 |
+ components: { |
|
149 |
+ SvgIcon, |
|
150 |
+ }, |
|
151 |
+ mounted() {}, |
|
152 |
+}; |
|
153 |
+</script> |
|
154 |
+<style scoped> |
|
155 |
+.mic-btn { |
|
156 |
+ cursor: pointer; |
|
157 |
+} |
|
158 |
+.mic-btn.notRecording { |
|
159 |
+ background-image: none; |
|
160 |
+ cursor: pointer; |
|
161 |
+} |
|
162 |
+.speakText { |
|
163 |
+ background-color: #fff8e9; |
|
164 |
+ border: 0; |
|
165 |
+} |
|
166 |
+.speakText span { |
|
167 |
+ font-size: 28px; |
|
168 |
+} |
|
169 |
+</style>(No newline at end of file) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?