speak_short
Convert short text (up to 100 characters) into speech instantly using Windows' built-in Speech API for quick and efficient auditory communication.
Instructions
짧은 텍스트를 즉시 읽어줍니다 (100자 이하)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes |
Implementation Reference
- windows_tts_mcp/main.py:281-298 (handler)Main handler for 'speak_short' tool. Validates text length (<=100 chars), spawns daemon thread to execute TTS via powershell_tts.@mcp.tool() def speak_short(text: str) -> str: """짧은 텍스트를 즉시 읽어줍니다 (100자 이하)""" try: if len(text) > 100: return "[ERROR] 텍스트가 너무 깁니다. speak를 사용하세요." def _speak_short(): powershell_tts(text) thread = threading.Thread(target=_speak_short, daemon=True) thread.start() return f"[SHORT] 짧은 텍스트 재생: '{text}'" except Exception as e: return f"[ERROR] 짧은 텍스트 재생 오류: {str(e)}"
- windows_tts_mcp/main.py:67-130 (helper)Core helper function that performs the actual TTS synthesis using PowerShell's System.Speech.Synthesis. Manages subprocess execution, threading locks for process tracking, timeouts, and error recovery. Called by speak_short.def powershell_tts(text: str, rate: int = 0, volume: int = 100) -> bool: """PowerShell을 사용한 TTS 실행""" process = None try: if platform.system() != "Windows": safe_print("[ERROR] Windows가 아닙니다") return False # 텍스트에서 작은따옴표 이스케이프 처리 escaped_text = text.replace("'", "''") # PowerShell TTS 명령어 cmd = [ "powershell", "-Command", f"Add-Type -AssemblyName System.Speech; " f"$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer; " f"$synth.Rate = {rate}; " f"$synth.Volume = {volume}; " f"$synth.Speak('{escaped_text}'); " f"$synth.Dispose()" ] # 프로세스 시작 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) # 실행 중인 프로세스 목록에 추가 with process_lock: running_processes.append(process) # 프로세스 완료 대기 stdout, stderr = process.communicate(timeout=180) # 완료된 프로세스 목록에서 제거 with process_lock: if process in running_processes: running_processes.remove(process) if process.returncode == 0: safe_print(f"[SUCCESS] TTS 완료: {text[:30]}...") return True else: safe_print(f"[ERROR] TTS 오류: {stderr}") return False except subprocess.TimeoutExpired: safe_print("[WARNING] TTS 시간 초과") if process: process.kill() with process_lock: if process in running_processes: running_processes.remove(process) return False except Exception as e: safe_print(f"[ERROR] TTS 예외: {e}") if process: try: process.kill() with process_lock: if process in running_processes: running_processes.remove(process) except: pass return False
- windows_tts_mcp/main.py:34-36 (helper)Global variables for managing running TTS processes and thread-safe locking, used by powershell_tts and other TTS functions including speak_short.# 실행 중인 TTS 프로세스 관리 running_processes = [] process_lock = threading.Lock()
- windows_tts_mcp/main.py:281-281 (registration)FastMCP decorator that registers the speak_short function as a tool.@mcp.tool()