Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: Misaki G2P
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
|
@@ -11,4 +11,4 @@ license: apache-2.0
|
|
| 11 |
short_description: G2P
|
| 12 |
---
|
| 13 |
|
| 14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: Misaki G2P
|
| 3 |
+
emoji: ⚡
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
|
|
|
| 11 |
short_description: G2P
|
| 12 |
---
|
| 13 |
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gradio_client import Client
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import pprint
|
| 6 |
+
import spaces
|
| 7 |
+
|
| 8 |
+
@spaces.GPU
|
| 9 |
+
def greet(n):
|
| 10 |
+
return f"Hello {zero + n} Tensor"
|
| 11 |
+
|
| 12 |
+
client = Client('hexgrad/misaki-src', hf_token=os.environ['TOKEN'])
|
| 13 |
+
def predict(text, use_spacy_transformer, british):
|
| 14 |
+
phonemes, trace, elapsed_cpu_time = client.predict(text=text, trf=use_spacy_transformer, british=british, api_name='/predict')
|
| 15 |
+
trace = pprint.pformat(json.loads(trace))
|
| 16 |
+
return phonemes, trace, elapsed_cpu_time
|
| 17 |
+
|
| 18 |
+
with gr.Blocks() as app:
|
| 19 |
+
gr.Markdown('''
|
| 20 |
+
Misaki is an experimental G2P engine designed to power future versions of Kokoro models.
|
| 21 |
+
|
| 22 |
+
This English-only preview is primarily intended for researchers and linguists. It may be deeply uninteresting to most people.
|
| 23 |
+
''', container=True)
|
| 24 |
+
gr.Interface(fn=predict, inputs=[gr.Text(), gr.Checkbox(), gr.Checkbox()],
|
| 25 |
+
outputs=[gr.Text(label='phonemes'), gr.Text(label='trace'), gr.Number(label='elapsed_cpu_time')])
|
| 26 |
+
gr.Markdown('''
|
| 27 |
+
### Examples
|
| 28 |
+
```md
|
| 29 |
+
American: [Misaki](/misˈɑki/) is an experimental G2P engine designed to power future versions of [Kokoro](/kˈOkəɹO/) models.
|
| 30 |
+
|
| 31 |
+
British: [Misaki](/misˈɑːki/) is an experimental G2P engine designed to power future versions of [Kokoro](/kˈQkəɹQ/) models.
|
| 32 |
+
|
| 33 |
+
But I am the Chosen One. But I [am](+1) the Chosen [One](-1). But I [am](+2) the Chosen [One](-2).
|
| 34 |
+
|
| 35 |
+
1002. [1002](#a#). [1002](#an#). [1002](#a&#). 2025. 2,025. $45.67 billion trillion.
|
| 36 |
+
```
|
| 37 |
+
''', container=True)
|
| 38 |
+
gr.Markdown('''
|
| 39 |
+
### Token-Level Trace
|
| 40 |
+
```py
|
| 41 |
+
# 1. Text. Can be useful for aligning text to phonemes, e.g. highlighting text during audio playback.
|
| 42 |
+
|
| 43 |
+
# 2. Tag. See a full list of tags from spaCy:
|
| 44 |
+
# https://github.com/explosion/spaCy/blob/master/spacy/glossary.py
|
| 45 |
+
|
| 46 |
+
# 3. Whitespace. Whether or not a token has trailing whitespace (string => bool for this demo).
|
| 47 |
+
whitespace = True if whitespace else False
|
| 48 |
+
|
| 49 |
+
# 4. Phonemes. For this demo, the question mark means UNK, the ninja emoji means empty string.
|
| 50 |
+
phonemes = '❓' if phonemes is None else ('🥷' if phonemes == '' else phonemes)
|
| 51 |
+
|
| 52 |
+
# 5. Rating. Star rating for the estimated quality of this token's phonemes.
|
| 53 |
+
ratings = dict(
|
| 54 |
+
user_override = '💎(5/5)',
|
| 55 |
+
gold = '🏆(4/5)',
|
| 56 |
+
silver = '🥈(3/5)',
|
| 57 |
+
bronze = '🥉(2/5)',
|
| 58 |
+
unk = '❓(UNK)',
|
| 59 |
+
)
|
| 60 |
+
```
|
| 61 |
+
''', container=True)
|
| 62 |
+
gr.Markdown('''
|
| 63 |
+
### Notes
|
| 64 |
+
- For English, Misaki uses a gold dictionary with 80k words and a similarly sized silver dictionary.
|
| 65 |
+
- There are separate dictionaries for American & British English.
|
| 66 |
+
- Users can override the dictionary and/or individual tokens with custom pronunciations.
|
| 67 |
+
- `espeak-ng` is used as the fallback for OOD words, and the token is rated "bronze" in this case.
|
| 68 |
+
- Raw token objects are returned, with phonemes aligned at the per-token level.
|
| 69 |
+
- UNKs are easy to detect when `token.phonemes is None`.
|
| 70 |
+
- The entire implementation of Misaki (English) is <1000 lines of Python, excluding dictionary files.
|
| 71 |
+
- POS disambiguation should be live, e.g. to wound someone vs wound up.
|
| 72 |
+
- use_spacy_transformer should deliver more reliable POS tags.
|
| 73 |
+
- Non-POS-based disambiguation, like graph axes vs throwing axes, is still a TODO.
|
| 74 |
+
''', container=True)
|
| 75 |
+
|
| 76 |
+
with gr.Blocks() as info:
|
| 77 |
+
gr.Markdown('''
|
| 78 |
+
# Misaki English Phonemes
|
| 79 |
+
|
| 80 |
+
For English, Misaki currently uses 49 total phonemes. Of these, 41 are shared by both Americans and Brits, 4 are American-only, and 4 are British-only.
|
| 81 |
+
|
| 82 |
+
Disclaimer: Author is an ML researcher, not a linguist, and may have butchered or reappropriated the traditional meaning of some symbols. These symbols are intended as input tokens for neural networks to yield optimal performance.
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
### 🤝 Shared (41)
|
| 86 |
+
|
| 87 |
+
**Stress Marks (2)**
|
| 88 |
+
- `ˈ`: Primary stress, visually looks similar to an apostrophe.
|
| 89 |
+
- `ˌ`: Secondary stress.
|
| 90 |
+
|
| 91 |
+
**IPA Consonants (22)**
|
| 92 |
+
- `bdfhjklmnpstvwz`: 15 alpha consonants taken from IPA. They mostly sound as you'd expect, but `j` actually represents the "y" sound, like `yes => jˈɛs`.
|
| 93 |
+
- `ɡ`: Hard "g" sound, like `get => ɡɛt`. Visually looks like the lowercase letter g, but its actually `U+0261`.
|
| 94 |
+
- `ŋ`: The "ng" sound, like `sung => sˈʌŋ`.
|
| 95 |
+
- `ɹ`: Upside-down r is just an "r" sound, like `red => ɹˈɛd`.
|
| 96 |
+
- `ʃ`: The "sh" sound, like `shin => ʃˈɪn`.
|
| 97 |
+
- `ʒ`: The "zh" sound, like `Asia => ˈAʒə`.
|
| 98 |
+
- `ð`: Soft "th" sound, like `than => ðən`.
|
| 99 |
+
- `θ`: Hard "th" sound, like `thin => θˈɪn`.
|
| 100 |
+
|
| 101 |
+
**Consonant Clusters (2)**
|
| 102 |
+
- `ʤ`: A "j" or "dg" sound, merges `dʒ`, like `jump => ʤˈʌmp` or `lunge => lˈʌnʤ`.
|
| 103 |
+
- `ʧ`: The "ch" sound, merges `tʃ`, like `chump => ʧˈʌmp` or `lunch => lˈʌnʧ`.
|
| 104 |
+
|
| 105 |
+
**IPA Vowels (10)**
|
| 106 |
+
- `ə`: The schwa is a common, unstressed vowel sound, like `a 🍌 => ə 🍌`.
|
| 107 |
+
- `i`: As in `easy => ˈizi`.
|
| 108 |
+
- `u`: As in `flu => flˈu`.
|
| 109 |
+
- `ɑ`: As in `spa => spˈɑ`.
|
| 110 |
+
- `ɔ`: As in `all => ˈɔl`.
|
| 111 |
+
- `ɛ`: As in `hair => hˈɛɹ` or `bed => bˈɛd`. Possibly dubious, because those vowel sounds do not sound similar to my ear.
|
| 112 |
+
- `ɜ`: As in `her => hɜɹ`. Easy to confuse with `ɛ` above.
|
| 113 |
+
- `ɪ`: As in `brick => bɹˈɪk`.
|
| 114 |
+
- `ʊ`: As in `wood => wˈʊd`.
|
| 115 |
+
- `ʌ`: As in `sun => sˈʌn`.
|
| 116 |
+
|
| 117 |
+
**Dipthong Vowels (4)**
|
| 118 |
+
- `A`: The "eh" vowel sound, like `hey => hˈA`. Expands to `eɪ` in IPA.
|
| 119 |
+
- `I`: The "eye" vowel sound, like `high => hˈI`. Expands to `aɪ` in IPA.
|
| 120 |
+
- `W`: The "ow" vowel sound, like `how => hˌW`. Expands to `aʊ` in IPA.
|
| 121 |
+
- `Y`: The "oy" vowel sound, like `soy => sˈY`. Expands to `ɔɪ` in IPA.
|
| 122 |
+
|
| 123 |
+
**Custom Vowel (1)**
|
| 124 |
+
- `ᵊ`: Small schwa, muted version of `ə`, like `pixel => pˈɪksᵊl`. I made this one up, so I'm not entirely sure if it's correct.
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
### 🇺🇸 American-only (4)
|
| 128 |
+
|
| 129 |
+
**Vowels (3)**
|
| 130 |
+
- `æ`: The vowel sound at the start of `ash => ˈæʃ`.
|
| 131 |
+
- `O`: Capital letter representing the American "oh" vowel sound. Expands to `oʊ` in IPA.
|
| 132 |
+
- `ᵻ`: A sound somewhere in between `ə` and `ɪ`, often used in certain -s suffixes like `boxes => bˈɑksᵻz`.
|
| 133 |
+
|
| 134 |
+
**Consonant (1)**
|
| 135 |
+
- `ɾ`: A sound somewhere in between `t` and `d`, like `butter => bˈʌɾəɹ`.
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
### 🇬🇧 British-only (4)
|
| 139 |
+
|
| 140 |
+
**Vowels (3)**
|
| 141 |
+
- `a`: The vowel sound at the start of `ash => ˈaʃ`.
|
| 142 |
+
- `Q`: Capital letter representing the British "oh" vowel sound. Expands to `əʊ` in IPA.
|
| 143 |
+
- `ɒ`: The sound at the start of `on => ˌɒn`. Easy to confuse with `ɑ`, which is a shared phoneme.
|
| 144 |
+
|
| 145 |
+
**Other (1)**
|
| 146 |
+
- `ː`: Vowel extender, visually looks similar to a colon. Possibly dubious, because Americans extend vowels too, but the gold US dictionary somehow lacks these. Often used by the Brits instead of `ɹ`: Americans say `or => ɔɹ`, but Brits say `or => ɔː`.
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
### ♻️ Misaki to espeak
|
| 150 |
+
```py
|
| 151 |
+
def to_espeak(ps):
|
| 152 |
+
# Optionally, you can add a tie character in between the 2 replacement characters.
|
| 153 |
+
ps = ps.replace('ʤ', 'dʒ').replace('ʧ', 'tʃ')
|
| 154 |
+
ps = ps.replace('A', 'eɪ').replace('I', 'aɪ').replace('Y', 'ɔɪ')
|
| 155 |
+
ps = ps.replace('O', 'oʊ').replace('Q', 'əʊ').replace('W', 'aʊ')
|
| 156 |
+
return ps.replace('ᵊ', 'ə')
|
| 157 |
+
```
|
| 158 |
+
''')
|
| 159 |
+
|
| 160 |
+
demo = gr.TabbedInterface(
|
| 161 |
+
[app, info],
|
| 162 |
+
['🔥 Misaki English Preview', 'ℹ️ Phonemes'],
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
demo.launch()
|