Created
June 8, 2021 02:45
-
-
Save JeromeNi/2d3118d9685a9ea4cdcc66d5bc8659c8 to your computer and use it in GitHub Desktop.
g2p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 -u | |
# Copyright (c) Facebook, Inc. and its affiliates. | |
# | |
# This source code is licensed under the MIT license found in the | |
# LICENSE file in the root directory of this source tree. | |
import argparse | |
import sys | |
from g2p_en import G2p | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument("root_dirs", nargs="*") | |
parser.add_argument("--insert-silence", "-s", action="store_true") | |
args = parser.parse_args() | |
sil = "<s>" | |
wrd_to_phn = {} | |
g2p = G2p() | |
for line in sys.stdin: | |
words = line.strip().split() | |
phones = [] | |
if args.insert_silence: | |
phones.append(sil) | |
for w in words: | |
if w not in wrd_to_phn: | |
wrd_to_phn[w] = g2p(w) | |
results = [] | |
for phn in wrd_to_phn[w]: | |
new_phn = ''.join([i for i in phn if not i.isdigit()]) | |
new_phn = ''.join([i for i in new_phn if i != "'"]) | |
if new_phn != '': | |
results.append(new_phn) | |
phones.extend(results) | |
if args.insert_silence: | |
phones.append(sil) | |
try: | |
print(" ".join(phones)) | |
except: | |
print(wrd_to_phn, w, phones, file=sys.stderr) | |
raise | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment