@supertone/supertone 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +119 -69
  2. package/custom_test/realtime_tts_player.ts +177 -12
  3. package/custom_test/test_pronunciation_dictionary.ts +227 -0
  4. package/custom_test/test_real_api.ts +1677 -162
  5. package/custom_test/test_text_utils_chunk_text_punctuation.ts +55 -0
  6. package/dist/commonjs/lib/config.d.ts +2 -2
  7. package/dist/commonjs/lib/config.d.ts.map +1 -1
  8. package/dist/commonjs/lib/config.js +2 -2
  9. package/dist/commonjs/lib/config.js.map +1 -1
  10. package/dist/commonjs/lib/custom_utils/index.d.ts +1 -0
  11. package/dist/commonjs/lib/custom_utils/index.d.ts.map +1 -1
  12. package/dist/commonjs/lib/custom_utils/index.js +5 -1
  13. package/dist/commonjs/lib/custom_utils/index.js.map +1 -1
  14. package/dist/commonjs/lib/custom_utils/pronunciation_utils.d.ts +24 -0
  15. package/dist/commonjs/lib/custom_utils/pronunciation_utils.d.ts.map +1 -0
  16. package/dist/commonjs/lib/custom_utils/pronunciation_utils.js +145 -0
  17. package/dist/commonjs/lib/custom_utils/pronunciation_utils.js.map +1 -0
  18. package/dist/commonjs/lib/custom_utils/text_utils.d.ts +8 -1
  19. package/dist/commonjs/lib/custom_utils/text_utils.d.ts.map +1 -1
  20. package/dist/commonjs/lib/custom_utils/text_utils.js +125 -7
  21. package/dist/commonjs/lib/custom_utils/text_utils.js.map +1 -1
  22. package/dist/commonjs/models/apiconverttexttospeechusingcharacterrequest.d.ts +92 -1
  23. package/dist/commonjs/models/apiconverttexttospeechusingcharacterrequest.d.ts.map +1 -1
  24. package/dist/commonjs/models/apiconverttexttospeechusingcharacterrequest.js +48 -3
  25. package/dist/commonjs/models/apiconverttexttospeechusingcharacterrequest.js.map +1 -1
  26. package/dist/commonjs/models/predictttsdurationusingcharacterrequest.d.ts +92 -1
  27. package/dist/commonjs/models/predictttsdurationusingcharacterrequest.d.ts.map +1 -1
  28. package/dist/commonjs/models/predictttsdurationusingcharacterrequest.js +46 -3
  29. package/dist/commonjs/models/predictttsdurationusingcharacterrequest.js.map +1 -1
  30. package/dist/commonjs/sdk/texttospeech.d.ts +17 -6
  31. package/dist/commonjs/sdk/texttospeech.d.ts.map +1 -1
  32. package/dist/commonjs/sdk/texttospeech.js +48 -25
  33. package/dist/commonjs/sdk/texttospeech.js.map +1 -1
  34. package/dist/esm/lib/config.d.ts +2 -2
  35. package/dist/esm/lib/config.d.ts.map +1 -1
  36. package/dist/esm/lib/config.js +2 -2
  37. package/dist/esm/lib/config.js.map +1 -1
  38. package/dist/esm/lib/custom_utils/index.d.ts +1 -0
  39. package/dist/esm/lib/custom_utils/index.d.ts.map +1 -1
  40. package/dist/esm/lib/custom_utils/index.js +2 -0
  41. package/dist/esm/lib/custom_utils/index.js.map +1 -1
  42. package/dist/esm/lib/custom_utils/pronunciation_utils.d.ts +24 -0
  43. package/dist/esm/lib/custom_utils/pronunciation_utils.d.ts.map +1 -0
  44. package/dist/esm/lib/custom_utils/pronunciation_utils.js +140 -0
  45. package/dist/esm/lib/custom_utils/pronunciation_utils.js.map +1 -0
  46. package/dist/esm/lib/custom_utils/text_utils.d.ts +8 -1
  47. package/dist/esm/lib/custom_utils/text_utils.d.ts.map +1 -1
  48. package/dist/esm/lib/custom_utils/text_utils.js +125 -7
  49. package/dist/esm/lib/custom_utils/text_utils.js.map +1 -1
  50. package/dist/esm/models/apiconverttexttospeechusingcharacterrequest.d.ts +92 -1
  51. package/dist/esm/models/apiconverttexttospeechusingcharacterrequest.d.ts.map +1 -1
  52. package/dist/esm/models/apiconverttexttospeechusingcharacterrequest.js +47 -2
  53. package/dist/esm/models/apiconverttexttospeechusingcharacterrequest.js.map +1 -1
  54. package/dist/esm/models/predictttsdurationusingcharacterrequest.d.ts +92 -1
  55. package/dist/esm/models/predictttsdurationusingcharacterrequest.d.ts.map +1 -1
  56. package/dist/esm/models/predictttsdurationusingcharacterrequest.js +45 -2
  57. package/dist/esm/models/predictttsdurationusingcharacterrequest.js.map +1 -1
  58. package/dist/esm/sdk/texttospeech.d.ts +17 -6
  59. package/dist/esm/sdk/texttospeech.d.ts.map +1 -1
  60. package/dist/esm/sdk/texttospeech.js +49 -26
  61. package/dist/esm/sdk/texttospeech.js.map +1 -1
  62. package/examples/custom_voices/create_cloned_voice.ts +4 -3
  63. package/examples/custom_voices/delete_custom_voice.ts +2 -7
  64. package/examples/custom_voices/edit_custom_voice.ts +2 -6
  65. package/examples/custom_voices/get_custom_voice.ts +2 -7
  66. package/examples/custom_voices/list_custom_voices.ts +2 -7
  67. package/examples/custom_voices/search_custom_voices.ts +2 -6
  68. package/examples/text_to_speech/create_speech.ts +3 -8
  69. package/examples/text_to_speech/create_speech_long_text.ts +3 -7
  70. package/examples/text_to_speech/create_speech_with_phonemes.ts +3 -7
  71. package/examples/text_to_speech/create_speech_with_voice_settings.ts +3 -8
  72. package/examples/text_to_speech/predict_duration.ts +3 -7
  73. package/examples/text_to_speech/stream_speech.ts +3 -7
  74. package/examples/text_to_speech/stream_speech_long_text.ts +3 -7
  75. package/examples/text_to_speech/stream_speech_with_phonemes.ts +3 -7
  76. package/examples/text_to_speech/stream_speech_with_voice_settings.ts +3 -7
  77. package/examples/usage/get_credit_balance.ts +2 -6
  78. package/examples/usage/get_usage.ts +2 -6
  79. package/examples/usage/get_voice_usage.ts +2 -7
  80. package/examples/voices/get_voice.ts +2 -6
  81. package/examples/voices/list_voices.ts +2 -6
  82. package/examples/voices/search_voices.ts +2 -7
  83. package/jsr.json +1 -1
  84. package/openapi.json +101 -9
  85. package/package.json +1 -1
  86. package/src/lib/config.ts +41 -41
  87. package/src/lib/custom_utils/index.ts +7 -0
  88. package/src/lib/custom_utils/pronunciation_utils.ts +193 -0
  89. package/src/lib/custom_utils/text_utils.ts +138 -7
  90. package/src/models/apiconverttexttospeechusingcharacterrequest.ts +62 -3
  91. package/src/models/predictttsdurationusingcharacterrequest.ts +64 -3
  92. package/src/sdk/texttospeech.ts +99 -68
@@ -0,0 +1,227 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Behavior tests for applyPronunciationDictionary().
4
+ *
5
+ * Run:
6
+ * npx ts-node custom_test/test_pronunciation_dictionary.ts
7
+ * # or after build:
8
+ * node dist/custom_test/test_pronunciation_dictionary.js
9
+ */
10
+
11
+ import {
12
+ applyPronunciationDictionary,
13
+ PronunciationDictionaryValidationError,
14
+ type PronunciationDictionaryEntry,
15
+ } from "../src/lib/custom_utils/pronunciation_utils.js";
16
+
17
+ function assertEqual(actual: string, expected: string, message: string): void {
18
+ if (actual !== expected) {
19
+ throw new Error(`${message}\nexpected=${expected}\nactual=${actual}`);
20
+ }
21
+ }
22
+
23
+ function assertThrows(fn: () => void, message: string): void {
24
+ let threw = false;
25
+ try {
26
+ fn();
27
+ } catch (e) {
28
+ threw = true;
29
+ if (!(e instanceof PronunciationDictionaryValidationError)) {
30
+ throw new Error(`${message}\nexpected PronunciationDictionaryValidationError`);
31
+ }
32
+ }
33
+ if (!threw) {
34
+ throw new Error(`${message}\nexpected to throw`);
35
+ }
36
+ }
37
+
38
+ function runTests(): void {
39
+ const d = (entries: PronunciationDictionaryEntry[]) => entries;
40
+
41
+ assertEqual(applyPronunciationDictionary("hello", undefined), "hello", "none returns original");
42
+ assertEqual(applyPronunciationDictionary("hello", []), "hello", "empty returns original");
43
+
44
+ assertEqual(
45
+ applyPronunciationDictionary("This is Supertone.", d([{ text: "Supertone", pronunciation: "super tone", partial_match: false }])),
46
+ "This is super tone.",
47
+ "basic exact match"
48
+ );
49
+
50
+ assertEqual(
51
+ applyPronunciationDictionary("K-TTS is different from TTSAPI.", d([{ text: "TTS", pronunciation: "text to speech", partial_match: true }])),
52
+ "K-text to speech is different from text to speechAPI.",
53
+ "partial match substrings"
54
+ );
55
+
56
+ assertEqual(
57
+ applyPronunciationDictionary("TTS and TTS and TTS.", d([{ text: "TTS", pronunciation: "text to speech", partial_match: true }])),
58
+ "text to speech and text to speech and text to speech.",
59
+ "multiple occurrences"
60
+ );
61
+
62
+ assertEqual(
63
+ applyPronunciationDictionary('He said, "Supertone", (Supertone)!', d([{ text: "Supertone", pronunciation: "super tone", partial_match: false }])),
64
+ 'He said, "super tone", (super tone)!',
65
+ "punctuation boundaries"
66
+ );
67
+
68
+ assertEqual(
69
+ applyPronunciationDictionary("API_test API test_API", d([{ text: "API", pronunciation: "A P I", partial_match: false }])),
70
+ "API_test A P I test_API",
71
+ "word boundary underscore"
72
+ );
73
+
74
+ assertEqual(
75
+ applyPronunciationDictionary("C++ is old, C++11 is newer.", d([{ text: "C++", pronunciation: "cplusplus", partial_match: false }])),
76
+ "cplusplus is old, C++11 is newer.",
77
+ "numbers break boundary"
78
+ );
79
+
80
+ assertEqual(
81
+ applyPronunciationDictionary("a(b)c a(b)c", d([{ text: "a(b)c", pronunciation: "X", partial_match: true }])),
82
+ "X X",
83
+ "regex meta chars"
84
+ );
85
+
86
+ assertEqual(
87
+ applyPronunciationDictionary("aaaa", d([{ text: "aa", pronunciation: "b", partial_match: true }])),
88
+ "bb",
89
+ "non-overlapping left-to-right"
90
+ );
91
+
92
+ assertEqual(
93
+ applyPronunciationDictionary("AAAA", d([
94
+ { text: "AA", pronunciation: "B", partial_match: true },
95
+ { text: "A", pronunciation: "C", partial_match: true },
96
+ ])),
97
+ "BB",
98
+ "order priority AA then A"
99
+ );
100
+
101
+ assertEqual(
102
+ applyPronunciationDictionary("AAAA", d([
103
+ { text: "A", pronunciation: "C", partial_match: true },
104
+ { text: "AA", pronunciation: "B", partial_match: true },
105
+ ])),
106
+ "CCCC",
107
+ "order priority A then AA"
108
+ );
109
+
110
+ assertEqual(
111
+ applyPronunciationDictionary("NY is not New Jersey.", d([
112
+ { text: "NY", pronunciation: "New York", partial_match: false },
113
+ { text: "New", pronunciation: "Old", partial_match: false },
114
+ ])),
115
+ "New York is not Old Jersey.",
116
+ "no resubstitution inside pronunciation"
117
+ );
118
+
119
+ assertEqual(
120
+ applyPronunciationDictionary("이번 APEC 은 한국에서 열립니다", d([
121
+ { text: "AP", pronunciation: "에이피", partial_match: true },
122
+ { text: "APEC", pronunciation: "에이팩", partial_match: true },
123
+ ])),
124
+ "이번 에이피EC 은 한국에서 열립니다",
125
+ "order AP then APEC"
126
+ );
127
+
128
+ assertEqual(
129
+ applyPronunciationDictionary("이번 APEC 은 한국에서 열립니다", d([
130
+ { text: "APEC", pronunciation: "에이팩", partial_match: true },
131
+ { text: "AP", pronunciation: "에이피", partial_match: true },
132
+ ])),
133
+ "이번 에이팩 은 한국에서 열립니다",
134
+ "order APEC then AP"
135
+ );
136
+
137
+ assertEqual(
138
+ applyPronunciationDictionary("Supertone tone", d([
139
+ { text: "Supertone", pronunciation: "super tone", partial_match: false },
140
+ { text: "tone", pronunciation: "TONE", partial_match: false },
141
+ ])),
142
+ "super tone TONE",
143
+ "no resubstitution across rules"
144
+ );
145
+
146
+ assertEqual(
147
+ applyPronunciationDictionary("TTS와 TTSAPI는 다릅니다.", d([{ text: "TTS", pronunciation: "text to speech", partial_match: true }])),
148
+ "text to speech와 text to speechAPI는 다릅니다.",
149
+ "Korean partial match"
150
+ );
151
+
152
+ assertEqual(
153
+ applyPronunciationDictionary("東京TTS東京", d([{ text: "TTS", pronunciation: "text to speech", partial_match: false }])),
154
+ "東京TTS東京",
155
+ "no boundary in Japanese exact"
156
+ );
157
+
158
+ assertEqual(
159
+ applyPronunciationDictionary("これは「TTS」です。", d([{ text: "TTS", pronunciation: "text to speech", partial_match: false }])),
160
+ "これは「text to speech」です。",
161
+ "boundary by punctuation Japanese"
162
+ );
163
+
164
+ assertEqual(
165
+ applyPronunciationDictionary("東京TTS東京", d([{ text: "TTS", pronunciation: "text to speech", partial_match: true }])),
166
+ "東京text to speech東京",
167
+ "partial match Japanese"
168
+ );
169
+
170
+ assertEqual(
171
+ applyPronunciationDictionary(`X \uE000PD0\uE001 Supertone`, d([{ text: "Supertone", pronunciation: "super tone", partial_match: false }])),
172
+ `X \uE000PD0\uE001 super tone`,
173
+ "token collision safe"
174
+ );
175
+
176
+ assertEqual(
177
+ applyPronunciationDictionary("TTS와 TTS.", d([{ text: "TTS", pronunciation: "text to speech", partial_match: false }])),
178
+ "TTS와 text to speech.",
179
+ "unicode boundary note"
180
+ );
181
+
182
+ assertThrows(
183
+ () => applyPronunciationDictionary("hi", {} as any),
184
+ "validation: dictionary must be array"
185
+ );
186
+
187
+ assertThrows(
188
+ () => applyPronunciationDictionary("hi", ["not-an-object"] as any),
189
+ "validation: entry must be object"
190
+ );
191
+
192
+ assertThrows(
193
+ () => applyPronunciationDictionary("hi", [{ text: 1, pronunciation: "b", partial_match: true }] as any),
194
+ "validation: text type"
195
+ );
196
+
197
+ assertThrows(
198
+ () => applyPronunciationDictionary("hi", [{ text: "a", pronunciation: 1, partial_match: true }] as any),
199
+ "validation: pronunciation type"
200
+ );
201
+
202
+ assertThrows(
203
+ () => applyPronunciationDictionary("hi", [{ text: "a", pronunciation: "b" }] as any),
204
+ "validation: missing partial_match"
205
+ );
206
+
207
+ assertThrows(
208
+ () => applyPronunciationDictionary("hi", [{ text: "a", pronunciation: "b", partial_match: "true" }] as any),
209
+ "validation: partial_match type"
210
+ );
211
+
212
+ assertThrows(
213
+ () => applyPronunciationDictionary("hi", [{ text: "", pronunciation: "b", partial_match: true }] as any),
214
+ "validation: empty text"
215
+ );
216
+
217
+ assertThrows(
218
+ () => applyPronunciationDictionary("hi", [{ text: "a", pronunciation: "", partial_match: true }] as any),
219
+ "validation: empty pronunciation"
220
+ );
221
+
222
+ console.log("OK: applyPronunciationDictionary tests passed");
223
+ }
224
+
225
+ runTests();
226
+
227
+