Skip to content

Commit

Permalink
Merge pull request #360 from cclauss/pre-commit
Browse files Browse the repository at this point in the history
Add pre-commit
  • Loading branch information
willwade authored Nov 4, 2024
2 parents 52b8ed7 + f7543ff commit 952ff1c
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 76 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/python_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ on:
types: [created] # Only publish on tagged releases

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pipx install pre-commit
- run: pre-commit install
- run: pre-commit run --all-files

test:
needs: [pre-commit]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -45,7 +54,7 @@ jobs:
runs-on: ubuntu-latest
needs: [test] # This ensures tests pass before build
permissions:
id-token: write
id-token: write

steps:
- uses: actions/checkout@v4
Expand All @@ -72,7 +81,7 @@ jobs:
needs: [build]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'created' # Only on release creation

steps:
- uses: actions/checkout@v4
- name: Set up Python
Expand Down
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Learn more about this config here: https://pre-commit.com/

# To enable these pre-commit hooks run:
# `pipx install pre-commit` or `brew install pre-commit`
# Then in the project root directory run `pre-commit install`

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
# - id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml
# - id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: file-contents-sorter
- id: fix-byte-order-marker
- id: forbid-new-submodules
- id: forbid-submodules
- id: mixed-line-ending
- id: pretty-format-json
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace

- repo: https://github.com/MarcoGorelli/auto-walrus
rev: 0.3.4
hooks:
- id: auto-walrus

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell # See pyproject.toml for args
additional_dependencies:
- tomli

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
hooks: # Format before linting
- id: ruff-format
# - id: ruff
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

pip install pyttsx3

> If you get installation errors , make sure you first upgrade your wheel version using :
> If you get installation errors , make sure you first upgrade your wheel version using :
`pip install --upgrade wheel`


## Features :
## Features :

- ✨Fully **OFFLINE** text to speech conversion
- 🎈 Choose among different voices installed in your system
Expand All @@ -30,11 +30,11 @@
- ❤️ Simple, powerful, & intuitive API


#### Linux installation requirements :
#### Linux installation requirements :

+ If you are on a linux system and if the voice output is not working , then :
+ If you are on a linux system and if the voice output is not working , then :

Install espeak and libespeak1 as shown below:
Install espeak and libespeak1 as shown below:

```
sudo apt update && sudo apt install espeak libespeak1
Expand All @@ -60,7 +60,7 @@ import pyttsx3
pyttsx3.speak("I will speak this text")
```


**Changing Voice , Rate and Volume :**

```python3
Expand Down
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Installation
pip install pyttsx3


> If you get installation errors , make sure you first upgrade your wheel version using :
> If you get installation errors , make sure you first upgrade your wheel version using :
`pip install --upgrade wheel`

**Linux installation requirements :**
#####################################

+ If you are on a linux system and if the voice output is not working , then :
+ If you are on a linux system and if the voice output is not working , then :

Install espeak and libespeak1 as shown below:
Install espeak and libespeak1 as shown below:

::

Expand All @@ -34,8 +34,8 @@ Usage :
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()


**Changing Voice , Rate and Volume :**

::
Expand Down
58 changes: 29 additions & 29 deletions docs/drivers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,58 @@ All drivers must implement the following factory function and driver interface.
.. function:: buildDriver(proxy : pyttsx3.driver.DriverProxy) -> pyttsx3.drivers.DriverDelegate

Instantiates delegate subclass declared in this module.

:param proxy: Proxy instance provided by a :class:`pyttsx3.Engine` instance.

.. class:: DriverDelegate

.. note:: The :class:`DriverDelegate` class is not actually declared in :mod:`pyttsx3.drivers` and cannot serve as a base class. It is only here for the purpose of documenting the interface all drivers must implement.

.. method:: __init__(proxy : pyttsx3.drivers.DriverProxy, *args, **kwargs) -> None

Constructor. Must store the proxy reference.

:param proxy: Proxy instance provided by the :func:`buildDriver` function.

.. method:: destroy() ->

Optional. Invoked by the :class:`pyttsx3.driver.DriverProxy` when it is being destroyed so this delegate can clean up any synthesizer resources. If not implemented, the proxy proceeds safely.

.. method:: endLoop() -> None

Immediately ends a running driver event loop.

.. method:: getProperty(name : string) -> object

Immediately gets the named property value. At least those properties listed in the :meth:`pyttsx3.Engine.getProperty` documentation must be supported.

:param name: Name of the property to query.
:return: Value of the property at the time of this invocation.

.. method:: say(text : unicode, name : string) -> None

Immediately speaks an utterance. The speech must be output according to the current property values applied at the time of this invocation. Before this method returns, it must invoke :meth:`pyttsx3.driver.DriverProxy.setBusy` with value :const:`True` to stall further processing of the command queue until the output completes or is interrupted.

This method must trigger one and only one `started-utterance` notification when output begins, one `started-word` notification at the start of each word in the utterance, and a `finished-utterance` notification when output completes.

:param text: Text to speak.
:param name: Name to associate with the utterance. Included in notifications about this utterance.

.. method:: setProperty(name : string, value : object) -> None

Immediately sets the named property value. At least those properties listed in the :meth:`pyttsx3.Engine.setProperty` documentation must be supported. After setting the property, the driver must invoke :meth:`pyttsx3.driver.DriverProxy.setBusy` with value :const:`False` to pump the command queue.

:param name: Name of the property to change.
:param value: Value to set.

.. method:: startLoop()

Immediately starts an event loop. The loop is responsible for sending notifications about utterances and pumping the command queue by using methods on the :class:`pyttsx3.driver.DriverProxy` object given to the factory function that created this object.

.. method:: stop()
Immediately stops the current utterance output. This method must trigger a `finished-utterance` notification if called during on-going output. It must trigger no notification if there is no ongoing output.

Immediately stops the current utterance output. This method must trigger a `finished-utterance` notification if called during on-going output. It must trigger no notification if there is no ongoing output.

After stopping the output and sending any required notification, the driver must invoke :meth:`pyttsx3.driver.DriverProxy.setBusy` with value :const:`False` to pump the command queue.

The DriverProxy interface
Expand All @@ -81,22 +81,22 @@ The DriverProxy interface
The :func:`pyttsx3.drivers.buildDriver` factory receives an instance of a :class:`DriverProxy` class and provides it to the :class:`pyttsx3.drivers.DriverDelegate` it constructs. The driver delegate can invoke the following public methods on the proxy instance. All other public methods found in the code are reserved for use by an :class:`pyttsx3.Engine` instance.

.. class:: DriverProxy

.. method:: isBusy() -> bool

Gets if the proxy is busy and cannot process the next command in the queue or not.

:return: True means busy, False means idle.

.. method:: notify(topic : string, **kwargs) -> None

Fires a notification.

:param topic: The name of the notification.
:kwargs: Name/value pairs associated with the topic.

.. method:: setBusy(busy : bool) -> None

Sets the proxy to busy so it cannot continue to pump the command queue or idle so it can process the next command.

:param busy: True to set busy, false to set idle
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ This documentation describes the pyttsx3 Python package v |release| and was rend

__ https://github.com/nateshmbhat/pyttsx3
__ http://pypi.python.org/pypi/pyttsx3
__ https://pyttsx3.readthedocs.org/
__ https://pyttsx3.readthedocs.org/
2 changes: 1 addition & 1 deletion docs/support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Version |version| of pyttsx3 includes drivers for the following text-to-speech s
* NSSpeechSynthesizer on Mac OS X 10.5 (Leopard) and 10.6 (Snow Leopard)
* espeak on Ubuntu Desktop Edition 8.10 (Intrepid), 9.04 (Jaunty), and 9.10 (Karmic)

The :func:`pyttsx3.init` documentation explains how to select a specific synthesizer by name as well as the default for each platform.
The :func:`pyttsx3.init` documentation explains how to select a specific synthesizer by name as well as the default for each platform.
12 changes: 7 additions & 5 deletions example/main.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
"""pyttsx3 examples"""

import pyttsx3

engine = pyttsx3.init() # object creation

""" RATE"""
# RATE
rate = engine.getProperty("rate") # getting details of current speaking rate
print(rate) # printing current voice rate
engine.setProperty("rate", 125) # setting up new voice rate


"""VOLUME"""
# VOLUME
volume = engine.getProperty(
"volume"
) # getting to know current volume level (min=0 and max=1)
print(volume) # printing current volume level
engine.setProperty("volume", 1.0) # setting up volume level between 0 and 1

"""VOICE"""
# VOICE
voices = engine.getProperty("voices") # getting details of current voice
# engine.setProperty('voice', voices[0].id) #changing index, changes voices. 0 for male
engine.setProperty(
"voice", voices[1].id
) # changing index, changes voices. 1 for female

"""PITCH"""
# PITCH
pitch = engine.getProperty("pitch") # Get current pitch value
print(pitch) # Print current pitch value
engine.setProperty("pitch", 75) # Set the pitch (default 50) to 75 out of 100
Expand All @@ -33,7 +35,7 @@
engine.stop()


"""Saving Voice to a file"""
# Saving Voice to a file
# On linux make sure that 'espeak' is installed
engine.save_to_file("Hello World", "test.mp3")
engine.runAndWait()
Loading

0 comments on commit 952ff1c

Please sign in to comment.