Python:
import os
from pygame import mixer
class UltraVoiceSkill(Skill):
def __init__(self):
super().__init__()
self.voices_folder = os.path.abspath("voices")
self._safe_chars = set("abcdefghijklmnopqrstuvwxyz0123456789 _-") # Allowed chars
mixer.init()
def input(self, ear: str, skin: str, eye: str):
# Fast exit for non-strings or empty input
if not isinstance(ear, str) or not ear.strip():
return
# 1. Lightning-fast sanitization
clean = ear.strip().lower().replace(" ", "_")
clean = ''.join(c for c in clean if c in self._safe_chars)
if not clean: # Empty after sanitization
return
# 2. Secure path construction
voice_path = os.path.join(self.voices_folder, f"{clean}.mp3")
# 3. Single validation check
if (os.path.normpath(voice_path).startswith(self.voices_folder)
and voice_path.endswith('.mp3')
and os.path.isfile(voice_path)):
mixer.music.load(voice_path)
mixer.music.play()