Fix voice preview not updating when age category changes

- Clear all cached previews for a role when age changes
- Clear all cached previews for a role when voice changes
- Now preview correctly reflects the selected age speed modifier
This commit is contained in:
2025-12-09 14:37:23 +00:00
parent 69eb0b3507
commit b5c53604a6

View File

@@ -164,27 +164,32 @@ export default function VoiceAssignmentSection({
const handleVoiceSelect = (roleId: string, voiceId: string) => { const handleVoiceSelect = (roleId: string, voiceId: string) => {
onVoiceChange(roleId, voiceId); onVoiceChange(roleId, voiceId);
// Clear cached preview when voice changes // Clear all cached previews for this role when voice changes
const cacheKey = `${roleId}-${voiceId}`;
setAudioCache(prev => { setAudioCache(prev => {
const newCache = new Map(prev); const newCache = new Map(prev);
newCache.delete(cacheKey); // Remove all cache entries that start with this roleId
Array.from(newCache.keys()).forEach(key => {
if (key.startsWith(`${roleId}-`)) {
newCache.delete(key);
}
});
return newCache; return newCache;
}); });
}; };
const handleAgeSelect = (roleId: string, age: AgeCategory) => { const handleAgeSelect = (roleId: string, age: AgeCategory) => {
onAgeChange(roleId, age); onAgeChange(roleId, age);
// Clear cached preview when age changes // Clear all cached previews for this role when age changes
const voiceId = voiceAssignments.get(roleId); setAudioCache(prev => {
if (voiceId) { const newCache = new Map(prev);
const cacheKey = `${roleId}-${voiceId}`; // Remove all cache entries that start with this roleId
setAudioCache(prev => { Array.from(newCache.keys()).forEach(key => {
const newCache = new Map(prev); if (key.startsWith(`${roleId}-`)) {
newCache.delete(cacheKey); newCache.delete(key);
return newCache; }
}); });
} return newCache;
});
}; };
const handlePreview = async (roleId: string) => { const handlePreview = async (roleId: string) => {