Skip to content

Commit

Permalink
Handle missing PortAudio system dependency
Browse files Browse the repository at this point in the history
And add info about PortAudio to the README file.
  • Loading branch information
paulovcmedeiros committed Nov 14, 2023
2 parents a33a15a + 0747ac1 commit fdc57bd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----
#----------------------------------------------
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ The package is written in Python. The web chatbot UI is made with [Streamlit](ht
- Python >= 3.9
- 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
Expand All @@ -68,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 .
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion pyrobbot/text_to_speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit fdc57bd

Please sign in to comment.