Converts a string of text to a sequence of IDs corresponding to the symbols in the text. The text can optionally have ARPAbet sequences enclosed in curly braces embedded in it. For example, "Turn left on {HH AW1 S S T AH0 N} Street." Args: text: string to convert to a sequence
(text, cleaner_names)
| 11 | |
| 12 | |
| 13 | def text_to_sequence(text, cleaner_names): |
| 14 | """Converts a string of text to a sequence of IDs corresponding to the symbols in the text. |
| 15 | |
| 16 | The text can optionally have ARPAbet sequences enclosed in curly braces embedded |
| 17 | in it. For example, "Turn left on {HH AW1 S S T AH0 N} Street." |
| 18 | |
| 19 | Args: |
| 20 | text: string to convert to a sequence |
| 21 | cleaner_names: names of the cleaner functions to run the text through |
| 22 | |
| 23 | Returns: |
| 24 | List of integers corresponding to the symbols in the text |
| 25 | """ |
| 26 | sequence = [] |
| 27 | |
| 28 | # Check for curly braces and treat their contents as ARPAbet: |
| 29 | while len(text): |
| 30 | m = _curly_re.match(text) |
| 31 | if not m: |
| 32 | sequence += _symbols_to_sequence(_clean_text(text, cleaner_names)) |
| 33 | break |
| 34 | sequence += _symbols_to_sequence(_clean_text(m.group(1), cleaner_names)) |
| 35 | sequence += _arpabet_to_sequence(m.group(2)) |
| 36 | text = m.group(3) |
| 37 | |
| 38 | # Append EOS token |
| 39 | sequence.append(_symbol_to_id["~"]) |
| 40 | return sequence |
| 41 | |
| 42 | |
| 43 | def sequence_to_text(sequence): |
no test coverage detected