Skip to content

Commit 1be0785

Browse files
Add dectalk to replace hardcoded test audio file
1 parent 976c3f1 commit 1be0785

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ GameData.json
55

66
# Dectalk plugin assets
77
dectalk/Lavalink.jar
8+
dectalk/*.wav
9+
dectalk/dectalk/
810

911
nppBackup
1012

PCBot/plugins/dectalk.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
import ongaku
2020
from ongaku.ext import checker
2121

22-
if not os.path.isfile('dectalk/Lavalink.jar'):
22+
if not os.path.isfile('dectalk/Lavalink.jar') or \
23+
not os.path.isfile('dectalk/dectalk/say'):
2324
raise Exception('Unable to find required dectalk files')
2425

2526
plugin = crescent.Plugin[hikari.GatewayBot, BotData]()
@@ -42,6 +43,14 @@ def start_lavalink():
4243
)
4344

4445

46+
def run_dectalk(text: str, guild_id: hikari.Snowflake) -> str:
47+
name = f'{guild_id}.wav'
48+
subprocess.run(
49+
['dectalk/dectalk/say', '-a', text, '-fo', f'dectalk/{name}']
50+
)
51+
return name
52+
53+
4554
async def fetch_player(guild_id: hikari.Snowflake) -> ongaku.Player | None:
4655
"""Return a functional ongaku player object."""
4756
# TODO: Figure out why player.connect fails with SessionStartException
@@ -88,7 +97,7 @@ class DecTalkCommand:
8897
Implemented by something sensible(somethingsensible).
8998
"""
9099

91-
# text = crescent.option(str, 'Text to speak')
100+
text = crescent.option(str, 'Text to speak')
92101
channel = crescent.option(
93102
hikari.GuildVoiceChannel, 'Channel to speak in', default=None
94103
)
@@ -97,6 +106,8 @@ async def callback(self, ctx: crescent.Context) -> None:
97106
"""Handle dectalk command being run."""
98107
sent_message = False
99108

109+
wav_name = run_dectalk(self.text, ctx.guild_id)
110+
100111
if self.channel is None:
101112
voice_state = ctx.client.app.cache.get_voice_state(
102113
ctx.guild_id, ctx.user.id
@@ -153,7 +164,7 @@ async def callback(self, ctx: crescent.Context) -> None:
153164
first_call = False
154165

155166
# TODO: Check if this is needed?
156-
checked_query = await checker.check('test.wav')
167+
checked_query = await checker.check(wav_name)
157168
if checked_query.type != checker.CheckedType.QUERY:
158169
await ctx.respond(
159170
'Failed to look for dectalk matches', ephemeral=True

dectalk/test.wav

-31 KB
Binary file not shown.

setupdectalk.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ download() {
1111
fi
1212
}
1313

14-
download "https://github.com/lavalink-devs/Lavalink/releases/download/4.0.4/Lavalink.jar" &&
15-
mv Lavalink.jar dectalk
14+
(download "https://github.com/lavalink-devs/Lavalink/releases/download/4.0.4/Lavalink.jar" &&
15+
mv Lavalink.jar dectalk) &
16+
(download "https://github.com/dectalk/dectalk/releases/download/2023-10-30/ubuntu-latest.tar.gz" &&
17+
mkdir -p dectalk/dectalk &&
18+
tar -C dectalk/dectalk -xf ubuntu-latest.tar.gz ./dic ./lib ./DECtalk.conf ./say &&
19+
rm ubuntu-latest.tar.gz) &
20+
wait

0 commit comments

Comments
 (0)