refactoring TTS code