mirror of
https://github.com/remsky/Kokoro-FastAPI.git
synced 2025-08-05 16:48:53 +00:00
Fix bug: same reference issue
This commit is contained in:
parent
5dbf2e2e4b
commit
655c243f1d
2 changed files with 5 additions and 5 deletions
|
@ -12,12 +12,12 @@ class AudioChunk:
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
audio: np.ndarray,
|
audio: np.ndarray, # dtype: np.int16
|
||||||
word_timestamps: Optional[List] = [],
|
word_timestamps: Optional[List] = None, # Using None instead of `[]` to avoid reference to the same empty list.
|
||||||
output: Optional[Union[bytes, np.ndarray]] = b"",
|
output: Optional[Union[bytes, np.ndarray]] = b"",
|
||||||
):
|
):
|
||||||
self.audio = audio
|
self.audio = audio
|
||||||
self.word_timestamps = word_timestamps
|
self.word_timestamps = word_timestamps if word_timestamps is not None else []
|
||||||
self.output = output
|
self.output = output
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -65,7 +65,7 @@ class TTSService:
|
||||||
# Handle silence tags, eg: `[silent](0.5s)`
|
# Handle silence tags, eg: `[silent](0.5s)`
|
||||||
if match := SILENCE_TAG.match(chunk_text):
|
if match := SILENCE_TAG.match(chunk_text):
|
||||||
silence_duration = float(match.group(1))
|
silence_duration = float(match.group(1))
|
||||||
silence_audio = np.zeros(int(silence_duration * 24000), dtype=np.float32)
|
silence_audio = np.zeros(int(silence_duration * 24000), dtype=np.int16)
|
||||||
if not output_format:
|
if not output_format:
|
||||||
yield AudioChunk(silence_audio, output=b"")
|
yield AudioChunk(silence_audio, output=b"")
|
||||||
return
|
return
|
||||||
|
@ -89,7 +89,7 @@ class TTSService:
|
||||||
return
|
return
|
||||||
chunk_data = await AudioService.convert_audio(
|
chunk_data = await AudioService.convert_audio(
|
||||||
AudioChunk(
|
AudioChunk(
|
||||||
np.array([], dtype=np.float32)
|
np.array([], dtype=np.int16)
|
||||||
), # Dummy data for type checking
|
), # Dummy data for type checking
|
||||||
output_format,
|
output_format,
|
||||||
writer,
|
writer,
|
||||||
|
|
Loading…
Add table
Reference in a new issue