Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

__init__.py 947 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  1. """ from https://github.com/keithito/tacotron """
  2. from text import cleaners
  3. def text_to_sequence(text, symbols, cleaner_names):
  4. '''Converts a string of text to a sequence of IDs corresponding to the symbols in the text.
  5. Args:
  6. text: string to convert to a sequence
  7. cleaner_names: names of the cleaner functions to run the text through
  8. Returns:
  9. List of integers corresponding to the symbols in the text
  10. '''
  11. _symbol_to_id = {s: i for i, s in enumerate(symbols)}
  12. sequence = []
  13. clean_text = _clean_text(text, cleaner_names)
  14. for symbol in clean_text:
  15. if symbol not in _symbol_to_id.keys():
  16. continue
  17. symbol_id = _symbol_to_id[symbol]
  18. sequence += [symbol_id]
  19. return sequence
  20. def _clean_text(text, cleaner_names):
  21. for name in cleaner_names:
  22. cleaner = getattr(cleaners, name)
  23. if not cleaner:
  24. raise Exception('Unknown cleaner: %s' % name)
  25. text = cleaner(text)
  26. return text
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...