From 591b05157db222755c96ceeb6a3f99975b1f961c Mon Sep 17 00:00:00 2001 From: Paulo V C Medeiros Date: Tue, 14 Nov 2023 07:39:09 +0100 Subject: [PATCH 1/4] Add PortAudio dep in test workflow --- .github/workflows/tests.yaml | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f59c8e4..fcc8035 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -35,6 +35,14 @@ jobs: - name: Check out repository uses: actions/checkout@v3 + #---------------------------------------------- + # Install PortAudio + #---------------------------------------------- + - name: Install PortAudio + run: | + apt-get update + apt-get --assume-yes install portaudio19-dev python-all-dev + #---------------------------------------------- # --- configure poetry & install project ---- #---------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 22369af..e9e9053 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ license = "MIT" name = "pyrobbot" readme = "README.md" - version = "0.2.0" + version = "0.2.1" [build-system] build-backend = "poetry.core.masonry.api" From de7ca2a88a7cab745571915f205d3d90bc3dd142 Mon Sep 17 00:00:00 2001 From: Paulo V C Medeiros Date: Tue, 14 Nov 2023 07:45:31 +0100 Subject: [PATCH 2/4] List PortAudio dep in readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b0fc612..6bddcee 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ The package is written in Python. The web chatbot UI is made with [Streamlit](ht ## System Requirements - Python >= 3.9 +- [PortAudio](https://www.portaudio.com/docs/v19-doxydocs/index.html) + - Required for voice chat + - Install on Ubuntu with `sudo apt-get --assume-yes install portaudio19-dev python-all-dev` - A valid [OpenAI API key](https://platform.openai.com/account/api-keys) - Set in the Web UI or through the environment variable `OPENAI_API_KEY` From c9187911462014db150510ab8c0307536f280a40 Mon Sep 17 00:00:00 2001 From: Paulo V C Medeiros Date: Tue, 14 Nov 2023 08:19:30 +0100 Subject: [PATCH 3/4] Handle soundservice import if portaudio not found --- README.md | 1 + pyrobbot/text_to_speech.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bddcee..7245afb 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ The package is written in Python. The web chatbot UI is made with [Streamlit](ht - [PortAudio](https://www.portaudio.com/docs/v19-doxydocs/index.html) - Required for voice chat - Install on Ubuntu with `sudo apt-get --assume-yes install portaudio19-dev python-all-dev` + - Install on CentOS/RHEL with `sudo yum install portaudio portaudio-devel` - A valid [OpenAI API key](https://platform.openai.com/account/api-keys) - Set in the Web UI or through the environment variable `OPENAI_API_KEY` diff --git a/pyrobbot/text_to_speech.py b/pyrobbot/text_to_speech.py index 48fc8ce..92c04a8 100644 --- a/pyrobbot/text_to_speech.py +++ b/pyrobbot/text_to_speech.py @@ -7,13 +7,23 @@ import numpy as np import pygame import scipy.io.wavfile as wav -import sounddevice as sd import soundfile as sf import speech_recognition as sr from gtts import gTTS from loguru import logger from pygame import mixer +try: + import sounddevice as sd + + _sounddevice_imported = True +except OSError as error: + logger.error(error) + logger.error( + "Can't use module `sounddevice`. Please check your system's PortAudio install." + ) + _sounddevice_imported = False + @dataclass class LiveAssistant: @@ -25,6 +35,12 @@ class LiveAssistant: inactivity_sound_intensity_threshold: float = 0.02 def __post_init__(self): + if not _sounddevice_imported: + logger.error( + "Module `sounddevice`, needed for audio recording, is not available." + ) + logger.error("Cannot continue. Exiting.") + raise SystemExit(1) mixer.init() def speak(self, text): From 0747ac1209fb7ec4576c1da9df331f606b94ec56 Mon Sep 17 00:00:00 2001 From: Paulo V C Medeiros Date: Tue, 14 Nov 2023 08:26:41 +0100 Subject: [PATCH 4/4] Update readme --- README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7245afb..f3d833e 100644 --- a/README.md +++ b/README.md @@ -40,14 +40,15 @@ The package is written in Python. The web chatbot UI is made with [Streamlit](ht ## System Requirements - Python >= 3.9 -- [PortAudio](https://www.portaudio.com/docs/v19-doxydocs/index.html) - - Required for voice chat - - Install on Ubuntu with `sudo apt-get --assume-yes install portaudio19-dev python-all-dev` - - Install on CentOS/RHEL with `sudo yum install portaudio portaudio-devel` - A valid [OpenAI API key](https://platform.openai.com/account/api-keys) - Set in the Web UI or through the environment variable `OPENAI_API_KEY` +- Optionally, to enable voice chat, you also need: + - [PortAudio](https://www.portaudio.com/docs/v19-doxydocs/index.html) + - Install on Ubuntu with `sudo apt-get --assume-yes install portaudio19-dev python-all-dev` + - Install on CentOS/RHEL with `sudo yum install portaudio portaudio-devel` ## Installation +This, naturally, assumes your systems fulfills all [requirements](#system-requirements). ### Using pip ```shell pip install pyrobbot @@ -72,16 +73,17 @@ and general `rob` options. For info about specific subcommands and the options that apply to them only, **please run `rob SUBCOMMAND -h`** (note that the `-h` goes after the subcommand in this case). -### Chatting by Voice -```shell -rob voice -``` ### Using the Web UI ```shell rob ``` +### Chatting by Voice +```shell +rob voice +``` + ### Running on the Terminal ```shell rob .