Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix for empty cache with diff device && ChatTTS process #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
tmp
cache
cache
asset
5 changes: 4 additions & 1 deletion STT/paraformer_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def process(self, spoken_prompt):
pred_text = (
self.model.generate(spoken_prompt)[0]["text"].strip().replace(" ", "")
)
torch.mps.empty_cache()
if self.device == "cuda":
torch.cuda.empty_cache()
elif self.device == "mps":
torch.mps.empty_cache()

logger.debug("finished paraformer inference")
console.print(f"[yellow]USER: {pred_text}")
Expand Down
12 changes: 8 additions & 4 deletions TTS/chatTTS_handler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import ChatTTS
import logging
from baseHandler import BaseHandler

import ChatTTS
import librosa
import numpy as np
from rich.console import Console
import torch
from rich.console import Console

from baseHandler import BaseHandler

logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
Expand Down Expand Up @@ -40,6 +42,8 @@ def warmup(self):
_ = self.model.infer("text")

def process(self, llm_sentence):
if isinstance(llm_sentence, tuple):
llm_sentence, language_code = llm_sentence
console.print(f"[green]ASSISTANT: {llm_sentence}")
if self.device == "mps":
import time
Expand All @@ -62,7 +66,7 @@ def process(self, llm_sentence):
self.should_listen.set()
return
audio_chunk = librosa.resample(gen[0], orig_sr=24000, target_sr=16000)
audio_chunk = (audio_chunk * 32768).astype(np.int16)[0]
audio_chunk = (audio_chunk * 32768).astype(np.int16)
while len(audio_chunk) > self.chunk_size:
yield audio_chunk[: self.chunk_size] # Return the first chunk_size samples of the audio data
audio_chunk = audio_chunk[self.chunk_size :] # Remove the samples that have already been returned
Expand Down