Skip to content

Commit

Permalink
Local TTS (#237)
Browse files Browse the repository at this point in the history
* Version 3.7.0
* Local TTS
    - Default to off
    - Can change default TTS model
* Update Readme for Local Dev
* Update .dockerignore
* 2024 License Bump 🐱
* Workflow Name Updates
* Verbose Build Output
* Fix Spell Timers Generation
    - Fix duplicate run bug on first run
    - Much faster
  • Loading branch information
mgeitz authored Mar 17, 2024
1 parent 5ea960c commit dfa46d0
Show file tree
Hide file tree
Showing 22 changed files with 4,650 additions and 187 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ MANIFEST
build/
*.pyc
.git
.github/
.gitignore
.venv/
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build eqalert
name: Build

on: push

Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
run: poetry install --without dev

- name: Build EQAlert
run: poetry build
run: poetry build -vvv | grep -vi ignoring

- name: Store Build Artifact
uses: actions/upload-artifact@v4
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Upload Python Package
name: Publish

on:
release:
Expand Down Expand Up @@ -41,5 +41,8 @@ jobs:
- name: Configure Token
run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}

- name: Build and Publish EQAlert
run: poetry publish --build
- name: Build
run: poetry build -vvv | grep -vi ignoring

- name: Publish
run: poetry publish
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test eqalert
name: Test

on: push

Expand Down
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ $ pipx install eqalert
$ eqalert
```

#### Locally
#### Docker
```sh
# Clone the repository
$ git clone https://github.com/mgeitz/eqalert.git
$ cd eqalert

# Build
$ docker compose build

# Start eqalert
$ docker compose run eqalert
```

#### Local Development
```sh
# Clone the repository
$ git clone https://github.com/mgeitz/eqalert.git
Expand All @@ -35,25 +48,15 @@ $ poetry run pip install --upgrade pip
$ poetry run pip install --upgrade wheel
$ poetry run pip install playsound

# Retrieve dependencies and build
# Retrieve dependencies
$ poetry update
$ poetry install
$ poetry build

# Start eqalert
$ poetry run eqalert
```

#### Docker
```sh
# Clone the repository
$ git clone https://github.com/mgeitz/eqalert.git
$ cd eqalert

# Build
$ docker compose build
$ poetry build

# Start eqalert
$ docker compose run eqalert
$ poetry run eqalert
```

> Note: If running through docker after installing and running on your host, update or regenerate `~/.eqa/config/settings.json` to reflect local container paths in `/home/eqalert`
Expand Down Expand Up @@ -190,8 +193,10 @@ Settings and options can be modified in `config/settings.json`
- `persist player data`: Save /who player output for spell timers
- `raid mode auto set`: Auto-set raid context by zone
- `speech expand lingo`: When speaking a line, replace common EQ abbreviations with complete words
- `speech lang`: The language (IETF language tag) to read the text in - [gTTS documentation reference](https://gtts.readthedocs.io/en/latest/module.html)
- `speech tld`: Top-level domain for the Google Translate host - [gTTS documentation reference](https://gtts.readthedocs.io/en/latest/module.html)
- `speech gtts lang`: The language (IETF language tag) to read the text in - [gTTS documentation reference](https://gtts.readthedocs.io/en/latest/module.html)
- `speech gtts tld`: Top-level domain for the Google Translate host - [gTTS documentation reference](https://gtts.readthedocs.io/en/latest/module.html)
- `speech local tts enabled`: If enabled, use the local TTS model to generate all speech. When disabled, use Google TTS. Enabling this requires a restart to take effect.
- `speech local tts model`: Coqui TTS model to use. A few good ones can be [found here](https://github.com/coqui-ai/TTS/discussions/1891), otherwise check the full [documentation](https://docs.coqui.ai/en/latest/index.html). Changing this requires a restart to take effect.
- `spell timer consolidate`: When a spell timer expires consolidate timers for the same spell in the next 3 seconds to one alert
- `spell timer delay`: Set a delay for all spell timer notifications n seconds before the actual event
- `spell timer filter by list`: If enabled only create spell timers for spells in filter list
Expand Down
26 changes: 22 additions & 4 deletions eqa/eqalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/eqalert.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -28,6 +28,8 @@
import time
import queue
import shutil
import torch
from TTS.api import TTS

import eqa.lib.action as eqa_action
import eqa.lib.config as eqa_config
Expand Down Expand Up @@ -212,6 +214,15 @@ def main():
+ configs.characters.config["char_logs"][char + "_" + server]["file_name"]
)

# If local tts ai is enabled, initialize
local_tts = None
if configs.settings.config["settings"]["speech"]["local_tts"]["enabled"]:
device = "cuda" if torch.cuda.is_available() else "cpu"
local_tts = TTS(
configs.settings.config["settings"]["speech"]["local_tts"]["model"],
progress_bar=False,
).to(device)

# Initialize curses
screen = eqa_curses.init(state, version)

Expand Down Expand Up @@ -337,12 +348,12 @@ def main():
process_encounter.daemon = True
process_encounter.start()

# Create Sounds, at most 3 sounds at once (sound blocking enabled)
# Create Sounds
## Consume sound_q
## Produce sounds
process_sound = threading.Thread(
target=eqa_sound.process,
args=(configs, sound_q, exit_flag, cfg_reload, state),
args=(configs, sound_q, exit_flag, cfg_reload, state, local_tts),
)
process_sound.daemon = True
process_sound.start()
Expand Down Expand Up @@ -813,7 +824,14 @@ def main():
#### Restart process_sound
process_sound = threading.Thread(
target=eqa_sound.process,
args=(configs, sound_q, exit_flag, cfg_reload, state),
args=(
configs,
sound_q,
exit_flag,
cfg_reload,
state,
local_tts,
),
)
process_sound.daemon = True
process_sound.start()
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/lib/action.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
46 changes: 31 additions & 15 deletions eqa/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/lib/config.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -13911,7 +13911,7 @@ def update_spell_timers(data_path, eq_spells_file_path, version):
generate_spell_timer_file = False

if generate_spell_timer_file:
print(" - generating spell-timers.json (this may take a minute)")
print(" - generating spell-timers.json")
# Bootstrap new spell-timers.json
spell_timer_json = {"spells": {}, "hash": spells_hash}

Expand All @@ -13930,10 +13930,12 @@ def update_spell_timers(data_path, eq_spells_file_path, version):
r"[^a-z\s]", "", spell_name.lower()
).replace(" ", "_")

## If spell is valid with a duration
if (
line_type_spell_name in valid_spells
and spell_buffdurationformula != "0"
):
### Write spell to timer file
spell_timer_json["spells"].update(
{
line_type_spell_name: {
Expand All @@ -13944,16 +13946,17 @@ def update_spell_timers(data_path, eq_spells_file_path, version):
}
)

spell_timer_json.update({"hash": spells_hash})
# Add spell timer version and file hash
spell_timer_json.update({"hash": spells_hash})
spell_timer_json.update({"version": version})

spell_timer_json.update({"version": version})

json_data = open(spell_timer_file, "w")
json.dump(spell_timer_json, json_data, sort_keys=True, indent=2)
json_data.close()
# Write spell timers
json_data = open(spell_timer_file, "w")
json.dump(spell_timer_json, json_data, sort_keys=True, indent=2)
json_data.close()
else:
print("Generating new spell-timers.json. This may take a minute . . .")
# Bootstrap new spell-timers.json
print(" - generating spell-timers.json")
spell_timer_json = {"spells": {}, "hash": spells_hash}

# Read spells_us.txt line
Expand All @@ -13971,7 +13974,11 @@ def update_spell_timers(data_path, eq_spells_file_path, version):
r"[^a-z\s]", "", spell_name.lower()
).replace(" ", "_")

if line_type_spell_name in valid_spells:
## If spell is valid with a duration
if (
line_type_spell_name in valid_spells
and spell_buffdurationformula != "0"
):
spell_timer_json["spells"].update(
{
line_type_spell_name: {
Expand All @@ -13982,9 +13989,14 @@ def update_spell_timers(data_path, eq_spells_file_path, version):
}
)

json_data = open(spell_timer_file, "w")
json.dump(spell_timer_json, json_data, sort_keys=True, indent=2)
json_data.close()
# Add spell timer version and file hash
spell_timer_json.update({"hash": spells_hash})
spell_timer_json.update({"version": version})

# Write spell timers
json_data = open(spell_timer_file, "w")
json.dump(spell_timer_json, json_data, sort_keys=True, indent=2)
json_data.close()

except Exception as e:
eqa_settings.log(
Expand Down Expand Up @@ -14494,8 +14506,12 @@ def build_config(base_path, version):
},
"speech": {
"expand_lingo": true,
"tld": "com",
"lang": "en"
"gtts_tld": "com",
"gtts_lang": "en",
"local_tts": {
"enabled": false,
"model": "tts_models/en/ljspeech/tacotron2-DDC_ph"
}
},
"timers": {
"mob": {
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/lib/curses.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/encounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/lib/encounter.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/lib/keys.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/lib/log.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/lib/parser.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion eqa/lib/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Program: EQ Alert
File Name: eqa/lib/settings.py
Copyright (C) 2023 M Geitz
Copyright (C) 2024 M Geitz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
Loading

0 comments on commit dfa46d0

Please sign in to comment.