-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·60 lines (53 loc) · 1.87 KB
/
main.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#! /usr/bin/env python3
# vim:fenc=utf-8
#
# Copyright © 2023 sandvich <sandvich@archtop>
#
# Distributed under terms of the GPLv3 license.
import sys
import click
@click.command()
@click.option("--cpu", is_flag=True, default=False, help="Enables/disables CPU inference")
@click.option("--threads", default=2, help="Number of threads (CPU only)")
@click.option("--stdin", is_flag=True, default=False, help="Read from standard input")
@click.option("--outfile", default="audio.wav", help="Audio file to write to")
def main(cpu, threads, stdin, outfile):
import tokens
from tokens import Token, Group
from tokenizer import Tokenizer
from bitcoin_miner import BitcoinMiner
bitcoin_miner = BitcoinMiner(not cpu, threads)
bitcoin_miner.update_model("udisen")
tokens.speech_synthesizer = bitcoin_miner
while True:
try:
# dash argument to read from stdin
if stdin:
line = sys.stdin.read().replace("\n", " ")
else:
print("-" * 50)
line = input()
if line == "":
continue
root = Group([])
Tokenizer(line, root).tokenize(root)
root.outfile = outfile
root.synthesize()
if stdin:
exit(0)
#if line.startswith("model:"):
# words = line.split(" ")
# speech = " ".join(words[1:])
# speaker = words[0].split(":")[-1]
# bitcoin_miner.update_model(speaker)
# line = speech
#audio = bitcoin_miner.end_to_end_infer(line, None)
#if audio is not None:
# sf.write("audio.wav", audio.to("cpu").numpy(), 22050)
except EOFError:
break
except KeyboardInterrupt:
print("Stopping...")
break
if __name__ == "__main__":
main()