fix: clear cached audio when voice selection changes
The preview button was caching audio but not invalidating the cache when the user selected a different voice, causing the same audio to play regardless of which voice was selected. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
093b55c473
commit
a999b23a17
1 changed files with 17 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { useState, useRef } from 'react';
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import { api } from '../lib/api';
|
||||
|
||||
interface VoicePreviewButtonProps {
|
||||
|
|
@ -14,6 +14,22 @@ export function VoicePreviewButton({ voiceName, language, disabled }: VoicePrevi
|
|||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
||||
const audioUrlRef = useRef<string | null>(null);
|
||||
|
||||
// Clear cached audio when voice or language changes
|
||||
useEffect(() => {
|
||||
// Stop any playing audio
|
||||
if (audioRef.current) {
|
||||
audioRef.current.pause();
|
||||
audioRef.current = null;
|
||||
}
|
||||
// Revoke old URL
|
||||
if (audioUrlRef.current) {
|
||||
URL.revokeObjectURL(audioUrlRef.current);
|
||||
audioUrlRef.current = null;
|
||||
}
|
||||
setIsPlaying(false);
|
||||
setError(null);
|
||||
}, [voiceName, language]);
|
||||
|
||||
const handlePreview = async () => {
|
||||
setError(null);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue