Fix : tts issues
This commit is contained in:
@@ -60,8 +60,8 @@ class Interaction:
|
||||
return buffer
|
||||
|
||||
def transcription_job(self):
|
||||
self.recorder = AudioRecorder()
|
||||
self.transcriber = AudioTranscriber(self.ai_name, verbose=False)
|
||||
self.recorder = AudioRecorder(verbose=True)
|
||||
self.transcriber = AudioTranscriber(self.ai_name, verbose=True)
|
||||
self.transcriber.start()
|
||||
self.recorder.start()
|
||||
self.recorder.join()
|
||||
@@ -71,7 +71,7 @@ class Interaction:
|
||||
|
||||
def get_user(self):
|
||||
if self.stt_enabled:
|
||||
query = self.transcription_job()
|
||||
query = "TTS transcription of user: " + self.transcription_job()
|
||||
else:
|
||||
query = self.read_stdin()
|
||||
if query is None:
|
||||
|
||||
+1
-2
@@ -20,8 +20,7 @@ class Memory():
|
||||
recover_last_session: bool = False,
|
||||
memory_compression: bool = True):
|
||||
self.memory = []
|
||||
self.memory = [{'role': 'user', 'content': system_prompt},
|
||||
{'role': 'assistant', 'content': f'Hello, How can I help you today ?'}]
|
||||
self.memory = [{'role': 'user', 'content': system_prompt}]
|
||||
|
||||
self.session_time = datetime.datetime.now()
|
||||
self.session_id = str(uuid.uuid4())
|
||||
|
||||
+8
-1
@@ -22,7 +22,14 @@ class AgentRouter:
|
||||
return "cpu"
|
||||
|
||||
def classify_text(self, text, threshold=0.5):
|
||||
result = self.pipeline(text, self.labels, threshold=threshold)
|
||||
first_sentence = None
|
||||
for line in text.split("\n"):
|
||||
if line.strip() != "":
|
||||
first_sentence = line.strip()
|
||||
break
|
||||
if first_sentence is None:
|
||||
first_sentence = text
|
||||
result = self.pipeline(first_sentence, self.labels, threshold=threshold)
|
||||
return result
|
||||
|
||||
def select_agent(self, text: str) -> Agent:
|
||||
|
||||
@@ -12,7 +12,7 @@ audio_queue = queue.Queue()
|
||||
done = False
|
||||
|
||||
class AudioRecorder:
|
||||
def __init__(self, format=pyaudio.paInt16, channels=1, rate=4096, chunk=8192, record_seconds=7, verbose=False):
|
||||
def __init__(self, format=pyaudio.paInt16, channels=1, rate=4096, chunk=8192, record_seconds=5, verbose=False):
|
||||
self.format = format
|
||||
self.channels = channels
|
||||
self.rate = rate
|
||||
@@ -90,7 +90,7 @@ class Transcript:
|
||||
|
||||
def remove_hallucinations(self, text: str):
|
||||
# TODO find a better way to do this
|
||||
common_hallucinations = ['Okay.', 'Thank you.', 'Thank you for watching.', 'You\'re', 'Oh', 'you', 'Oh.', 'Uh', 'Oh,', 'Mh-hmm', 'Hmm.']
|
||||
common_hallucinations = ['Okay.', 'Thank you.', 'Thank you for watching.', 'You\'re', 'Oh', 'you', 'Oh.', 'Uh', 'Oh,', 'Mh-hmm', 'Hmm.', 'going to.', 'not.']
|
||||
for hallucination in common_hallucinations:
|
||||
text = text.replace(hallucination, "")
|
||||
return text
|
||||
@@ -140,15 +140,15 @@ class AudioTranscriber:
|
||||
while not done or not audio_queue.empty():
|
||||
try:
|
||||
audio_data, sample_rate = audio_queue.get(timeout=1.0)
|
||||
if self.verbose:
|
||||
print(Fore.BLUE + "AudioTranscriber: Processing audio chunk" + Fore.RESET)
|
||||
|
||||
start_time = time.time()
|
||||
text = self.transcriptor.transcript_job(audio_data, sample_rate)
|
||||
end_time = time.time()
|
||||
self.recorded += text
|
||||
print(Fore.YELLOW + f"Transcribed: {text}" + Fore.RESET)
|
||||
print(Fore.YELLOW + f"Transcribed: {text} in {end_time - start_time} seconds" + Fore.RESET)
|
||||
for language, words in self.trigger_words.items():
|
||||
if any(word in text.lower() for word in words):
|
||||
print(Fore.GREEN + f"Start listening..." + Fore.RESET)
|
||||
print(Fore.GREEN + f"Listening again..." + Fore.RESET)
|
||||
self.recorded = text
|
||||
for language, words in self.confirmation_words.items():
|
||||
if any(word in text.lower() for word in words):
|
||||
|
||||
@@ -5,9 +5,10 @@ import subprocess
|
||||
import re
|
||||
import platform
|
||||
|
||||
|
||||
|
||||
class Speech():
|
||||
"""
|
||||
Speech is a class for generating speech from text.
|
||||
"""
|
||||
def __init__(self, language = "english") -> None:
|
||||
self.lang_map = {
|
||||
"english": 'a',
|
||||
@@ -24,6 +25,9 @@ class Speech():
|
||||
self.speed = 1.2
|
||||
|
||||
def speak(self, sentence, voice_number = 1):
|
||||
"""
|
||||
Use AI model to generate speech from text after pre-processing the text.
|
||||
"""
|
||||
sentence = self.clean_sentence(sentence)
|
||||
self.voice = self.voice_map["english"][voice_number]
|
||||
generator = self.pipeline(
|
||||
@@ -42,17 +46,39 @@ class Speech():
|
||||
winsound.PlaySound(audio_file, winsound.SND_FILENAME)
|
||||
|
||||
def replace_url(self, m):
|
||||
"""
|
||||
Replace URL with empty string.
|
||||
"""
|
||||
domain = m.group(1)
|
||||
if re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', domain):
|
||||
return ''
|
||||
return domain
|
||||
|
||||
def extract_filename(self, m):
|
||||
"""
|
||||
Extract filename from path.
|
||||
"""
|
||||
path = m.group()
|
||||
parts = re.split(r'/|\\', path)
|
||||
return parts[-1] if parts else path
|
||||
|
||||
def shorten_paragraph(self, sentence):
|
||||
"""
|
||||
Shorten paragraph like **explaination**: <long text> by keeping only the first sentence.
|
||||
"""
|
||||
lines = sentence.split('\n')
|
||||
lines_edited = []
|
||||
for line in lines:
|
||||
if line.startswith('**'):
|
||||
lines_edited.append(line.split('.')[0])
|
||||
else:
|
||||
lines_edited.append(line)
|
||||
return '\n'.join(lines_edited)
|
||||
|
||||
def clean_sentence(self, sentence):
|
||||
"""
|
||||
Clean sentence by removing URLs, filenames, and other non-alphanumeric characters.
|
||||
"""
|
||||
lines = sentence.split('\n')
|
||||
filtered_lines = [line for line in lines if re.match(r'^\s*[a-zA-Z]', line)]
|
||||
sentence = ' '.join(filtered_lines)
|
||||
|
||||
Reference in New Issue
Block a user