|
|
import sounddevice as sd
|
|
|
import numpy as np
|
|
|
from scipy.io.wavfile import write
|
|
|
import keyboard
|
|
|
import os
|
|
|
import time
|
|
|
|
|
|
|
|
|
emotion = "SURPRISED"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
txt_file = os.path.join(current_dir, f"{emotion}.txt")
|
|
|
|
|
|
|
|
|
|
|
|
save_folder = os.path.join(current_dir, "..", "wav_dataset", emotion)
|
|
|
|
|
|
|
|
|
fs = 24000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(save_folder):
|
|
|
os.makedirs(save_folder)
|
|
|
print(f"์๋ฆผ: '{save_folder}' ํด๋๋ฅผ ์์ฑํ์ต๋๋ค.")
|
|
|
|
|
|
|
|
|
if not os.path.exists(txt_file):
|
|
|
print(f"์ค๋ฅ: ๋๋ณธ ํ์ผ '{txt_file}'์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
|
|
exit()
|
|
|
|
|
|
with open(txt_file, 'r', encoding='utf-8') as f:
|
|
|
lines = [line.strip() for line in f.readlines() if line.strip()]
|
|
|
|
|
|
print(f"\n=== [{emotion}] ๋
น์ ์์ (์ด {len(lines)}๋ฌธ์ฅ) ===")
|
|
|
print(f"์ ์ฅ ๊ฒฝ๋ก: {save_folder}")
|
|
|
print("์ฌ์ฉ๋ฒ: 'Spacebar'๋ฅผ ๋๋ฅด๊ณ ์๋ ๋์ ๋
น์๋ฉ๋๋ค. ๋ผ๋ฉด ์ ์ฅ๋ฉ๋๋ค.")
|
|
|
print("์ค๋จํ๋ ค๋ฉด 'ESC'๋ฅผ ๋๋ฅด์ธ์.\n")
|
|
|
|
|
|
for i, text in enumerate(lines):
|
|
|
|
|
|
filename = f"{emotion}_{i + 1:03d}.wav"
|
|
|
filepath = os.path.join(save_folder, filename)
|
|
|
|
|
|
|
|
|
if os.path.exists(filepath):
|
|
|
print(f"[Skip] {filename} ์ด๋ฏธ ์กด์ฌํจ ({i + 1}/{len(lines)})")
|
|
|
continue
|
|
|
|
|
|
print(f"\n[{i + 1}/{len(lines)}] ๋ฌธ์ฅ ์ฝ์ผ์ธ์:")
|
|
|
print(f"๐ \033[96m{text}\033[0m")
|
|
|
print("(Spacebar๋ฅผ ๊พน ๋๋ฅด๊ณ ๋งํ์ธ์...)")
|
|
|
|
|
|
|
|
|
recording = []
|
|
|
|
|
|
|
|
|
while True:
|
|
|
if keyboard.is_pressed('esc'):
|
|
|
print("\n๋
น์ ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค.")
|
|
|
exit()
|
|
|
if keyboard.is_pressed('space'):
|
|
|
break
|
|
|
time.sleep(0.01)
|
|
|
|
|
|
|
|
|
|
|
|
def callback(indata, frames, time, status):
|
|
|
if status:
|
|
|
print(status)
|
|
|
recording.append(indata.copy())
|
|
|
|
|
|
|
|
|
|
|
|
with sd.InputStream(samplerate=fs, channels=1, callback=callback):
|
|
|
while keyboard.is_pressed('space'):
|
|
|
sd.sleep(10)
|
|
|
|
|
|
|
|
|
if recording:
|
|
|
my_recording = np.concatenate(recording, axis=0)
|
|
|
write(filepath, fs, my_recording)
|
|
|
print(f"โ
์ ์ฅ ์๋ฃ: {filename}")
|
|
|
else:
|
|
|
print("โ ๏ธ ๋
น์๋ ๋ด์ฉ์ด ์์ต๋๋ค. ๋ค์ ์๋ํ์ธ์.")
|
|
|
i -= 1
|
|
|
|
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
|
print("\n=== ๋ชจ๋ ๋
น์์ด ์๋ฃ๋์์ต๋๋ค! ๊ณ ์ํ์
จ์ต๋๋ค. ===") |