| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Fenrir TTY screen reader |
| 5 |
# By Chrys, Storm Dragon, and contributors. |
| 6 |
|
| 7 |
|
| 8 |
def parse_synthesis_voice_line(voice_line): |
| 9 |
"""Parse one column-aligned spd-say synthesis voice row.""" |
| 10 |
fields = voice_line.rsplit(maxsplit=2) |
| 11 |
if len(fields) != 3: |
| 12 |
return None |
| 13 |
|
| 14 |
name, language, variant = (field.strip() for field in fields) |
| 15 |
if not name: |
| 16 |
return None |
| 17 |
return name, language, variant |
| 18 |
|
| 19 |
|
| 20 |
def get_synthesis_voice_name(module, voice_line): |
| 21 |
"""Return the value Speech Dispatcher expects for voice selection.""" |
| 22 |
voice_data = parse_synthesis_voice_line(voice_line) |
| 23 |
if voice_data is None: |
| 24 |
return None |
| 25 |
|
| 26 |
name, language, variant = voice_data |
| 27 |
if module.lower() != "espeak-ng": |
| 28 |
return name |
| 29 |
|
| 30 |
language = language.lower() |
| 31 |
variant = variant.lower() |
| 32 |
if not language: |
| 33 |
return None |
| 34 |
if variant and variant != "none": |
| 35 |
return f"{language}+{variant}" |
| 36 |
return language |