@@ -48,6 +48,12 @@ import {
48
48
} from "./templates.ts" ;
49
49
import debounce from "lodash/debounce.js" ;
50
50
import { getWavHeader } from "./utils.ts" ;
51
+ import {
52
+ hexagramData ,
53
+ trigramFigures ,
54
+ trigramDescriptions ,
55
+ trigramChineseMapping ,
56
+ } from "@ai16z/agent/data/hexagrams.ts" ;
51
57
52
58
// These values are chosen for compatibility with picovoice components
53
59
const DECODE_FRAME_SIZE = 1024 ;
@@ -822,6 +828,11 @@ export class VoiceManager extends EventEmitter {
822
828
return ;
823
829
}
824
830
831
+ // Translate any I-Ching symbols before text-to-speech
832
+ if ( response . text ) {
833
+ response . text = this . translateIdeograms ( response . text ) ;
834
+ }
835
+
825
836
await this . runtime . databaseAdapter . log ( {
826
837
body : { message, context, response } ,
827
838
userId : userId ,
@@ -1036,4 +1047,48 @@ export class VoiceManager extends EventEmitter {
1036
1047
await interaction . reply ( "Failed to leave the voice channel." ) ;
1037
1048
}
1038
1049
}
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
+ }
1039
1094
}
0 commit comments