|
import argparse |
|
import os |
|
import requests |
|
import subprocess |
|
|
|
|
|
|
|
|
|
def command_line_args(): |
|
parser = argparse.ArgumentParser( |
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter |
|
) |
|
parser.add_argument( |
|
'--affective', |
|
help="Select Emotional or non-emotional variant of Available voices: https://audeering.github.io/shift/", |
|
action='store_false', |
|
) |
|
parser.add_argument( |
|
'--device', |
|
help="Device ID", |
|
type=str, |
|
default='cpu', |
|
) |
|
parser.add_argument( |
|
'--text', |
|
help="Text to be synthesized.", |
|
default='How is hoowl', |
|
type=str, |
|
) |
|
return parser |
|
|
|
def send_to_server(args): |
|
url = "http://192.168.88.209:5000" |
|
|
|
payload = { |
|
'text': args.text, |
|
'scene': args.scene |
|
} |
|
|
|
response = requests.post(url, data=payload) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response |
|
|
|
|
|
def cli(): |
|
parser = command_line_args() |
|
args = parser.parse_args() |
|
os.system('cls' if os.name == 'nt' else 'clear') |
|
while True: |
|
args.text = input("\n\n\n\nDescribe Any Sound: \n\n\n\n") |
|
|
|
|
|
args.scene = args.text |
|
if len(args.text) >= 4: |
|
response = send_to_server(args) |
|
out_file = '_gen_.wav' |
|
with open(out_file, 'wb') as f: |
|
f.write(response.content) |
|
subprocess.run(["paplay", out_file]) |
|
else: |
|
print(f'__\n{args.text}\n') |
|
|
|
|
|
if __name__ == '__main__': |
|
cli() |
|
|