Skip to content

Commit b57f69a

Browse files
committed
replace ideograms with names
1 parent 7578099 commit b57f69a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

packages/client-discord/src/voice.ts

+55
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ import {
4848
} from "./templates.ts";
4949
import debounce from "lodash/debounce.js";
5050
import { getWavHeader } from "./utils.ts";
51+
import {
52+
hexagramData,
53+
trigramFigures,
54+
trigramDescriptions,
55+
trigramChineseMapping,
56+
} from "@ai16z/agent/data/hexagrams.ts";
5157

5258
// These values are chosen for compatibility with picovoice components
5359
const DECODE_FRAME_SIZE = 1024;
@@ -822,6 +828,11 @@ export class VoiceManager extends EventEmitter {
822828
return;
823829
}
824830

831+
// Translate any I-Ching symbols before text-to-speech
832+
if (response.text) {
833+
response.text = this.translateIdeograms(response.text);
834+
}
835+
825836
await this.runtime.databaseAdapter.log({
826837
body: { message, context, response },
827838
userId: userId,
@@ -1036,4 +1047,48 @@ export class VoiceManager extends EventEmitter {
10361047
await interaction.reply("Failed to leave the voice channel.");
10371048
}
10381049
}
1050+
1051+
private translateIdeograms(text: string): string {
1052+
// Create reverse mappings
1053+
const trigramByFigure = Object.entries(trigramFigures).reduce(
1054+
(acc, [name, figure]) => {
1055+
acc[figure] = name;
1056+
return acc;
1057+
},
1058+
{} as Record<string, string>
1059+
);
1060+
1061+
const trigramByChinese = Object.entries(trigramChineseMapping).reduce(
1062+
(acc, [name, chinese]) => {
1063+
acc[chinese] = name;
1064+
return acc;
1065+
},
1066+
{} as Record<string, string>
1067+
);
1068+
1069+
const hexagramByUnicode = hexagramData.reduce(
1070+
(acc, hex) => {
1071+
acc[hex.unicode] = `${hex.meaning} (${hex.name.pinyin})`;
1072+
return acc;
1073+
},
1074+
{} as Record<string, string>
1075+
);
1076+
1077+
// Replace trigram figures (☰, ☱, etc)
1078+
text = text.replace(/[]/g, (match) =>
1079+
trigramByFigure[match] ? `${trigramByFigure[match]}` : match
1080+
);
1081+
1082+
// Replace trigram Chinese characters (乾, 兌, etc)
1083+
text = text.replace(/[]/g, (match) =>
1084+
trigramByChinese[match] ? `${trigramByChinese[match]}` : match
1085+
);
1086+
1087+
// Replace hexagram characters (䷀-䷿)
1088+
text = text.replace(/[-䷿]/g, (match) =>
1089+
hexagramByUnicode[match] ? `${hexagramByUnicode[match]}` : match
1090+
);
1091+
1092+
return text;
1093+
}
10391094
}

0 commit comments

Comments
 (0)