import gradio as gr from pocket_tts import TTSModel import pocket_tts import numpy as np # ✅ 핵심: 'data' 창고를 강제로 엽니다 (Explicit Import) import pocket_tts.data print("⏳ 모델 로딩 중...") model = TTSModel.load_model() print("✅ 모델 로드 완료.") # =================================================== # 🕵️‍♂️ [창고 털기] pocket_tts.data 내부 수색 # =================================================== print("\n" + "="*40) print("📦 [DEBUG] 'pocket_tts.data' 창고 개방") # 창고 안에 무엇이 있는지 리스트를 뽑습니다. data_contents = dir(pocket_tts.data) print(f"창고 내용물: {data_contents}") # 창고 안에서 'voices', 'speakers', 'catalog' 같은 단어를 찾습니다. found_voices = None for item_name in data_contents: if item_name in ['speakers', 'voices', 'catalog', 'predefined_voices']: print(f"✅ 유력한 용의자 발견: pocket_tts.data.{item_name}") found_voices = getattr(pocket_tts.data, item_name) break print("="*40 + "\n") def generate_speech(text): if not text: return (24000, np.zeros(24000)) # 1. 목소리 데이터 확보 시도 voice_state = None # 전략 A: 창고에서 찾은 목록(found_voices)이 딕셔너리라면 거기서 'alba'를 꺼냅니다. if found_voices and isinstance(found_voices, dict) and 'alba' in found_voices: print("🎉 성공! 창고 목록에서 'alba'를 찾았습니다.") voice_state = found_voices['alba'] # 전략 B: 만약 창고 털기에 실패했다면, 'alba'라는 이름표라도 붙여서 보냅니다. # (일부 버전에서는 이것이 통할 수도 있음) if voice_state is None: print("⚠️ 창고에서 데이터를 찾지 못해, 기본 이름표('alba')를 사용합니다.") # 주의: 이전에 실패했던 방식이지만, 구조를 파악하기 위해 남겨둡니다. voice_state = 'alba' try: # 2. 음성 생성 print(f"🗣️ 음성 생성 시도 (데이터 타입: {type(voice_state)})") audio = model.generate_audio(voice_state, text) return (model.sample_rate, audio.numpy()) except Exception as e: print(f"❌ 생성 실패: {e}") return (24000, np.zeros(24000)) # 3. UI 구성 with gr.Blocks(title="🚀 issamTTS (Data Warehouse)") as demo: gr.Markdown("## 📦 창고(Data Module) 수색 모드") gr.Markdown("Logs 탭에서 **'창고 내용물'** 리스트를 확인해 주세요. 그 안에 정답이 있습니다.") input_text = gr.Textbox(label="텍스트", value="박성한 이사님, 창고 문을 열었습니다. 안에 무엇이 있습니까?") btn = gr.Button("수색 및 생성 (Search & Generate)") output_audio = gr.Audio() btn.click(fn=generate_speech, inputs=[input_text], outputs=[output_audio]) if __name__ == "__main__": demo.launch()