From 290b75de3ff57482f8a3b71a2d2304516cd2cd48 Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Tue, 18 Mar 2025 20:19:28 +0530 Subject: [PATCH 1/7] Update text_to_speech.py updated the speak function , make it more sturctured , also added to play sound using afplay in macos and redirected linux or other to aplay , make sure the display of audio only work for jupyter notebooks not in terminal. the name of audio file is directly used in code , standerized it. --- sources/text_to_speech.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sources/text_to_speech.py b/sources/text_to_speech.py index 58f716b..cd590bb 100644 --- a/sources/text_to_speech.py +++ b/sources/text_to_speech.py @@ -4,6 +4,7 @@ import soundfile as sf import subprocess import re import platform +from sys import modules class Speech(): """ @@ -24,7 +25,7 @@ class Speech(): self.voice = self.voice_map[language][2] self.speed = 1.2 - def speak(self, sentence: str, voice_number: int = 1): + def speak(self, sentence: str, voice_number: int = 1 , audio_file: str = 'sample.wav'): """ Convert text to speech using an AI model and play the audio. @@ -38,17 +39,17 @@ class Speech(): sentence, voice=self.voice, speed=self.speed, split_pattern=r'\n+' ) - for i, (gs, ps, audio) in enumerate(generator): - audio_file = 'sample.wav' - display(Audio(data=audio, rate=24000, autoplay=i==0), display_id=False) + for i, (_, _, audio) in enumerate(generator): + if 'ipykernel' in modules: #only display in jupyter notebook. + display(Audio(data=audio, rate=24000, autoplay=i==0), display_id=False) sf.write(audio_file, audio, 24000) # save each audio file if platform.system().lower() == "windows": import winsound winsound.PlaySound(audio_file, winsound.SND_FILENAME) - elif platform.system().lower() == "linux": - subprocess.call(["aplay", audio_file]) - else: + elif platform.system().lower() == "darwin": # macOS subprocess.call(["afplay", audio_file]) + else: # linux or other. + subprocess.call(["aplay", audio_file]) def replace_url(self, url: re.Match) -> str: """ From 9d57d0568c1217cbd0e43400c7f3c42302a9897f Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Tue, 18 Mar 2025 20:40:23 +0530 Subject: [PATCH 2/7] Update requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f7182a3..81751aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ pyaudio==0.2.14 librosa==0.10.2.post1 selenium==4.29.0 markdownify==1.1.0 +chromedriver-autoinstaller==0.6.4 httpx>=0.27,<0.29 anyio>=3.5.0,<5 distro>=1.7.0,<2 @@ -29,4 +30,4 @@ tqdm>4 ordered_set pypinyin cn2an -jieba \ No newline at end of file +jieba From d12b345fe83b555df8832fa841b430d0573fe241 Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Tue, 18 Mar 2025 20:41:51 +0530 Subject: [PATCH 3/7] Update browser.py it automatically install chromedriver , if version is outdated or the chromedriver not found. --- sources/browser.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sources/browser.py b/sources/browser.py index 9a5acd3..add58c0 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -5,6 +5,7 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException, WebDriverException +import chromedriver_autoinstaller import time import os import shutil @@ -36,6 +37,9 @@ class Browser: chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") + + # Automatically find ChromeDriver path + chromedriver_autoinstaller.install() # Automatically find ChromeDriver path chromedriver_path = shutil.which("chromedriver") if not chromedriver_path: From 07a04b069ea756ab1defe51ed85597b9742395d9 Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Tue, 18 Mar 2025 20:49:26 +0530 Subject: [PATCH 4/7] Update browser.py update the code to remove overhead of check and install chromedriver. --- sources/browser.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sources/browser.py b/sources/browser.py index add58c0..d0190bf 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -8,7 +8,6 @@ from selenium.common.exceptions import TimeoutException, WebDriverException import chromedriver_autoinstaller import time import os -import shutil from bs4 import BeautifulSoup import markdownify import logging @@ -38,10 +37,8 @@ class Browser: chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") - # Automatically find ChromeDriver path - chromedriver_autoinstaller.install() - # Automatically find ChromeDriver path - chromedriver_path = shutil.which("chromedriver") + # Automatically install or find ChromeDriver path. + chromedriver_path = chromedriver_autoinstaller.install() if not chromedriver_path: raise FileNotFoundError("ChromeDriver not found. Please install it or add it to your PATH.") service = Service(chromedriver_path) From f71e4acf7ee8d71ab98766729a53d7c8dea5b35a Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Tue, 18 Mar 2025 21:28:34 +0530 Subject: [PATCH 5/7] Update requirements.txt From 088e324b88342e8212f4b3ea26d005e5cfa73e7f Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Tue, 18 Mar 2025 23:07:39 +0530 Subject: [PATCH 6/7] Update browser.py added both methods, for support for beta to. --- sources/browser.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sources/browser.py b/sources/browser.py index d0190bf..1c1c566 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -8,6 +8,7 @@ from selenium.common.exceptions import TimeoutException, WebDriverException import chromedriver_autoinstaller import time import os +import shutil from bs4 import BeautifulSoup import markdownify import logging @@ -36,9 +37,12 @@ class Browser: chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") - - # Automatically install or find ChromeDriver path. - chromedriver_path = chromedriver_autoinstaller.install() + # Automatically install or find ChromeDriver path.(for google chrome and chrome beta). + try: + chromedriver_path = chromedriver_autoinstaller.install() + except FileNotFoundError as e: + chromedriver_path = shutil.which("chromedriver") + if not chromedriver_path: raise FileNotFoundError("ChromeDriver not found. Please install it or add it to your PATH.") service = Service(chromedriver_path) From 2418894dcb299e40b9142654ac19abecbf4fec30 Mon Sep 17 00:00:00 2001 From: ganesh nikhil <73976037+ganeshnikhil@users.noreply.github.com> Date: Wed, 19 Mar 2025 01:16:25 +0530 Subject: [PATCH 7/7] Update browser.py --- sources/browser.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sources/browser.py b/sources/browser.py index 1c1c566..fe49680 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -37,14 +37,16 @@ class Browser: chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") - # Automatically install or find ChromeDriver path.(for google chrome and chrome beta). - try: + + chromedriver_path = shutil.which("chromedriver") # system installed driver. + + #If not found, try auto-installing the correct version + if not chromedriver_path: chromedriver_path = chromedriver_autoinstaller.install() - except FileNotFoundError as e: - chromedriver_path = shutil.which("chromedriver") - + if not chromedriver_path: raise FileNotFoundError("ChromeDriver not found. Please install it or add it to your PATH.") + service = Service(chromedriver_path) self.driver = webdriver.Chrome(service=service, options=chrome_options) self.wait = WebDriverWait(self.driver, 10)