Skip to content

Commit dd851d1

Browse files
willwadearjan
authored andcommitted
feat: Add Google comprehensive test suite and google:style tag support
- Created comprehensive test suite for Google Cloud TTS with 17 tests - Added support for google:style tag - Maps to google:style SSML tag - No namespace declaration needed per Google documentation - 16 tests passing, 1 skipped (voice sections not yet supported) - All 702 existing tests still passing
1 parent fa91dff commit dd851d1

File tree

4 files changed

+393
-0
lines changed

4 files changed

+393
-0
lines changed

google-ssml-examples.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Full
2+
3+
<speak>
4+
Here are <say-as interpret-as="characters">SSML</say-as> samples.
5+
I can pause <break time="3s"/>.
6+
I can play a sound
7+
<audio src="https://www.example.com/MY_MP3_FILE.mp3">didn't get your MP3 audio file</audio>.
8+
I can speak in cardinals. Your number is <say-as interpret-as="cardinal">10</say-as>.
9+
Or I can speak in ordinals. You are <say-as interpret-as="ordinal">10</say-as> in line.
10+
Or I can even speak in digits. The digits for ten are <say-as interpret-as="characters">10</say-as>.
11+
I can also substitute phrases, like the <sub alias="World Wide Web Consortium">W3C</sub>.
12+
Finally, I can speak a paragraph with two sentences.
13+
</speak>
14+
15+
16+
dates
17+
18+
<speak>
19+
<say-as interpret-as="date" format="yyyymmdd" detail="1">
20+
1960-09-10
21+
</say-as>
22+
</speak>
23+
24+
expletive
25+
26+
<speak>
27+
<say-as interpret-as="expletive">censor this</say-as>
28+
</speak>
29+
30+
Audio attachment
31+
32+
<speak>
33+
<audio src="cat_purr_close.ogg">
34+
<desc>a cat purring</desc>
35+
PURR (sound didn't load)
36+
</audio>
37+
</speak>
38+
39+
Marks
40+
41+
<speak>
42+
Go from <mark name="here"/> here, to <mark name="there"/> there!
43+
</speak>
44+
45+
46+
Prosody
47+
48+
<prosody rate="slow" pitch="-2st">Can you hear me now?</prosody>
49+
50+
Emphasis
51+
52+
<emphasis level="moderate">This is an important announcement</emphasis>
53+
54+
55+
IPA
56+
57+
<phoneme alphabet="ipa" ph="ˌmænɪˈtoʊbə">manitoba</phoneme>
58+
<phoneme alphabet="x-sampa" ph='m@"hA:g@%ni:'>mahogany</phoneme>
59+
60+
61+
Voice tags
62+
63+
<speak>And then she asked, <voice language="fr-FR" gender="female">qu'est-ce qui
64+
t'amène ici</voice><break time="250ms"/> in her sweet and gentle voice.</speak>
65+
66+
Langs in a speak
67+
68+
69+
<speak>The french word for cat is <lang xml:lang="fr-FR">chat</lang></speak>
70+
71+
72+
Style
73+
74+
<speak><google:style name="lively">Hello I'm so happy today!</google:style></speak>

src/formatters/GoogleAssistantSsmlFormatter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export class GoogleAssistantSsmlFormatter extends SsmlFormatterBase {
1111
this.modifierKeyToSsmlTagMappings.interjection = null;
1212
this.modifierKeyToSsmlTagMappings.whisper = 'prosody';
1313
this.modifierKeyToSsmlTagMappings.lang = 'lang';
14+
// Map style modifier to google:style tag
15+
this.modifierKeyToSsmlTagMappings.style = 'google:style';
1416
}
1517

1618
// tslint:disable-next-line: max-func-body-length
@@ -98,6 +100,10 @@ export class GoogleAssistantSsmlFormatter extends SsmlFormatterBase {
98100
textModifierObject.voiceTag(key, value);
99101
break;
100102

103+
case 'style':
104+
textModifierObject.tag(ssmlTag, { name: value });
105+
break;
106+
101107
default: {
102108
}
103109
}

test-google-style-check.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { SpeechMarkdown } = require('./dist/src/SpeechMarkdown.js');
2+
3+
const speech = new SpeechMarkdown();
4+
5+
console.log('=== Test Google Style (no namespace) ===');
6+
const markdown = `(Hello I'm so happy today!)[style:"lively"]`;
7+
const ssml = speech.toSSML(markdown, { platform: 'google-assistant' });
8+
console.log(JSON.stringify(ssml));
9+
console.log(ssml);
10+
11+
// Check that namespace is NOT present
12+
if (ssml.includes('xmlns:google')) {
13+
console.log('\n✗ ERROR: Google namespace found (should not be there)');
14+
} else {
15+
console.log('\n✓ Correct: No namespace in speak tag');
16+
}
17+
18+
if (ssml.includes('<google:style name="lively">')) {
19+
console.log('✓ google:style tag found!');
20+
} else {
21+
console.log('✗ google:style tag NOT found');
22+
}

0 commit comments

Comments
 (0)