Skip to content

Commit

Permalink
Fix #1719 Add bug chat sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami committed Feb 2, 2025
1 parent 8181fc7 commit 759bc47
Show file tree
Hide file tree
Showing 63 changed files with 105 additions and 7 deletions.
7 changes: 6 additions & 1 deletion client/bug/roundCtrl.bug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import {BoardName, BugBoardName, JSONObject, PyChessModel} from "../types";
import { GameControllerBughouse } from "./gameCtrl.bug";
import { BLACK, getTurnColor, uci2LastMove, WHITE } from "../chess";
import { sound } from "../sound";
import { sound, soundThemeSettings } from "../sound";
import { player } from "../player";
import { WebsocketHeartbeatJs } from '../socket/socket';
import { notify } from "../notification";
Expand Down Expand Up @@ -399,6 +399,8 @@ export class RoundControllerBughouse implements ChatController {
Mousetrap.bind('down', () => selectMove(this, this.steps.length - 1));
Mousetrap.bind('f', () => this.flipBoards());
Mousetrap.bind('?', () => this.helpDialog());

soundThemeSettings.buildBugChatSounds();
}

helpDialog() {
Expand Down Expand Up @@ -1171,6 +1173,9 @@ export class RoundControllerBughouse implements ChatController {
private onMsgChat = (msg: StepChat) => {
if (this.spectator /*spectators always see everything*/ || (!this.spectator && msg.room !== 'spectator') || msg.username.length === 0) {
chatMessageBug(this.ply, this, msg);
if (msg.username !== this.username && msg.message.startsWith("!bug!")) {
sound.bugChatSound(msg.message.replace('!bug!',''));
}
}
}

Expand Down
57 changes: 51 additions & 6 deletions client/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ class Sounds {
Berserk: 'Berserk',
};

private static readonly bugTrackNames = {
p: 'pawn',
n: 'knight',
b: 'bishop',
r: 'rook',
q: 'queen',
h: 'horse',
e: 'elephant',
// c: 'chariot',
c: 'cannon',
a: 'advisor',
nop: 'no-pawn',
non: 'no-knight',
nob: 'no-bishop',
nor: 'no-rook',
noq: 'no-queen',
noh: 'no-horse',
noe: 'no-elephant',
// noc: 'no-chariot',
noc: 'no-cannon',
noa: 'no-advisor',
sit: 'sit',
go: 'go',
trade: 'trade',
notrade: 'dont-trade',
mate: 'checkmate',
ok: 'ok',
no: 'no',
mb: 'my-bad',
nvm: 'nevermind',
nice: 'nice',
};

tracks: { [key: string]: Howl };

constructor() {
Expand All @@ -42,14 +75,20 @@ class Sounds {
});
}

buildBugChatSounds(assetURL: string) {
Object.keys(Sounds.bugTrackNames).forEach( (key: keyof typeof Sounds.bugTrackNames) => {
this.tracks[key] = this.buildSound(assetURL, 'bugchat', Sounds.bugTrackNames[key]);
});
}

updateSoundTheme(assetURL: string) {
const soundTheme = soundThemeSettings.value;
Object.keys(Sounds.trackNames).forEach( (key: keyof typeof Sounds.trackNames) => {
this.tracks[key] = this.buildSound(assetURL, Sounds.trackNames[key]);
this.tracks[key] = this.buildSound(assetURL, soundTheme, Sounds.trackNames[key]);
});
}

private buildSound(assetURL: string, trackName: string) {
const soundTheme = soundThemeSettings.value;
private buildSound(assetURL: string, soundTheme: string, trackName: string) {
const soundTrack = (soundTheme === 'silent') ? 'Silence' : trackName;
const sound = new Howl({
src: [
Expand Down Expand Up @@ -87,12 +126,16 @@ class Sounds {
explosion() { if (this.audio()) this.tracks.Explosion.play(); }
berserk() { if (this.audio()) this.tracks.Berserk.play(); }

bugchat(msg:string) { if (this.audio()) this.tracks[msg].play(); }

private moveSoundSet: {[k:string]: { move: ()=> void; capture: ()=>void;}} = {
regular: { move: () => this.move(), capture: () => this.capture() },
shogi: { move: () => this.shogimove(), capture: () => this.shogicapture() },
atomic: { move: () => this.move(), capture: () => this.explosion() },
};

bugChatSound(msg: string) { this.bugchat(msg) }

moveSound(variant: Variant, capture: boolean) {
const soundSet = variant.ui.pieceSound in this.moveSoundSet? this.moveSoundSet[variant.ui.pieceSound] : this.moveSoundSet.regular;
if (capture)
Expand Down Expand Up @@ -121,7 +164,7 @@ class Sounds {
}
}

gameEndSoundBughouse(result: string, team: '1' | '2') {
gameEndSoundBughouse(result: string, team: '1' | '2') {
switch (result) {
case "1/2-1/2":
this.draw();
Expand All @@ -140,8 +183,6 @@ class Sounds {
break;
}
}


}

class VolumeSettings extends NumberSettings {
Expand Down Expand Up @@ -181,6 +222,10 @@ class SoundThemeSettings extends StringSettings {
sound.updateSoundTheme(this.assetURL);
}

buildBugChatSounds(): void {
sound.buildBugChatSounds(this.assetURL);
}

view(): VNode {
return h('div#soundtheme.radio-list', radioList(this, 'soundtheme', soundThemes, (_, key) => this.value = key));
}
Expand Down
Binary file added static/sound/bugchat/advisor.mp3
Binary file not shown.
Binary file added static/sound/bugchat/advisor.ogg
Binary file not shown.
Binary file added static/sound/bugchat/bishop.mp3
Binary file not shown.
Binary file added static/sound/bugchat/bishop.ogg
Binary file not shown.
48 changes: 48 additions & 0 deletions static/sound/bugchat/bugchat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/sh

# Install ffmpeg from https://www.ffmpeg.org/download.html
# Install piper from https://github.com/rhasspy/piper

# Download two files per voice from https://github.com/rhasspy/piper/blob/master/VOICES.md

# A .onnx model file, such as en_US-lessac-medium.onnx
# A .onnx.json config file, such as en_US-lessac-medium.onnx.json


#model="en_US-lessac-medium.onnx"
#model="en_US-amy-medium.onnx"
model="en_GB-northern_english_male-medium.onnx"

MP3BITRATE="196k"
OGGBITRATE="32k"

for word in 'pawn' 'knight' 'bishop' 'rook' 'queen' 'horse' 'elephant' 'chariot' 'cannon' 'advisor'
do
no_word="no '$word'"

echo "$word" | ./piper --model "$model" --output_file "$word".wav
ffmpeg -i "$word".wav -acodec libmp3lame -b:a "$MP3BITRATE" "$word".mp3
ffmpeg -i "$word".wav -acodec libvorbis -b:a "$OGGBITRATE" "$word".ogg

echo "$no_word" | ./piper --model "$model" --output_file no-"$word".wav
ffmpeg -i no-"$word".wav -acodec libmp3lame -b:a "$MP3BITRATE" no-"$word".mp3
ffmpeg -i no-"$word".wav -acodec libvorbis -b:a "$OGGBITRATE" no-"$word".ogg

done

for word in 'sit' 'go' 'trade' 'checkmate' 'ok' 'no' 'nevermind' 'nice'
do
echo "$word" | ./piper --model "$model" --output_file "$word".wav
ffmpeg -i "$word".wav -acodec libmp3lame -b:a "$MP3BITRATE" "$word".mp3
ffmpeg -i "$word".wav -acodec libvorbis -b:a "$OGGBITRATE" "$word".ogg
done

word="dont-trade"
echo "don't trade" | ./piper --model "$model" --output_file "$word".wav
ffmpeg -i "$word".wav -acodec libmp3lame -b:a "$MP3BITRATE" "$word".mp3
ffmpeg -i "$word".wav -acodec libvorbis -b:a "$OGGBITRATE" "$word".ogg

word="my-bad"
echo "my bad" | ./piper --model "$model" --output_file "$word".wav
ffmpeg -i "$word".wav -acodec libmp3lame -b:a "$MP3BITRATE" "$word".mp3
ffmpeg -i "$word".wav -acodec libvorbis -b:a "$OGGBITRATE" "$word".ogg
Binary file added static/sound/bugchat/cannon.mp3
Binary file not shown.
Binary file added static/sound/bugchat/cannon.ogg
Binary file not shown.
Binary file added static/sound/bugchat/chariot.mp3
Binary file not shown.
Binary file added static/sound/bugchat/chariot.ogg
Binary file not shown.
Binary file added static/sound/bugchat/checkmate.mp3
Binary file not shown.
Binary file added static/sound/bugchat/checkmate.ogg
Binary file not shown.
Binary file added static/sound/bugchat/dont-trade.mp3
Binary file not shown.
Binary file added static/sound/bugchat/dont-trade.ogg
Binary file not shown.
Binary file added static/sound/bugchat/elephant.mp3
Binary file not shown.
Binary file added static/sound/bugchat/elephant.ogg
Binary file not shown.
Binary file added static/sound/bugchat/go.mp3
Binary file not shown.
Binary file added static/sound/bugchat/go.ogg
Binary file not shown.
Binary file added static/sound/bugchat/horse.mp3
Binary file not shown.
Binary file added static/sound/bugchat/horse.ogg
Binary file not shown.
Binary file added static/sound/bugchat/knight.mp3
Binary file not shown.
Binary file added static/sound/bugchat/knight.ogg
Binary file not shown.
Binary file added static/sound/bugchat/my-bad.mp3
Binary file not shown.
Binary file added static/sound/bugchat/my-bad.ogg
Binary file not shown.
Binary file added static/sound/bugchat/nevermind.mp3
Binary file not shown.
Binary file added static/sound/bugchat/nevermind.ogg
Binary file not shown.
Binary file added static/sound/bugchat/nice.mp3
Binary file not shown.
Binary file added static/sound/bugchat/nice.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-advisor.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-advisor.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-bishop.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-bishop.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-cannon.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-cannon.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-chariot.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-chariot.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-elephant.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-elephant.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-horse.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-horse.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-knight.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-knight.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-pawn.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-pawn.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-queen.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-queen.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no-rook.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no-rook.ogg
Binary file not shown.
Binary file added static/sound/bugchat/no.mp3
Binary file not shown.
Binary file added static/sound/bugchat/no.ogg
Binary file not shown.
Binary file added static/sound/bugchat/ok.mp3
Binary file not shown.
Binary file added static/sound/bugchat/ok.ogg
Binary file not shown.
Binary file added static/sound/bugchat/pawn.mp3
Binary file not shown.
Binary file added static/sound/bugchat/pawn.ogg
Binary file not shown.
Binary file added static/sound/bugchat/queen.mp3
Binary file not shown.
Binary file added static/sound/bugchat/queen.ogg
Binary file not shown.
Binary file added static/sound/bugchat/rook.mp3
Binary file not shown.
Binary file added static/sound/bugchat/rook.ogg
Binary file not shown.
Binary file added static/sound/bugchat/sit.mp3
Binary file not shown.
Binary file added static/sound/bugchat/sit.ogg
Binary file not shown.
Binary file added static/sound/bugchat/trade.mp3
Binary file not shown.
Binary file added static/sound/bugchat/trade.ogg
Binary file not shown.

0 comments on commit 759bc47

Please sign in to comment.