File size: 1,619 Bytes
bb2cd38
 
 
6e78f43
 
 
bb2cd38
6e78f43
 
 
 
 
 
bb2cd38
 
 
 
 
 
 
6e78f43
 
bb2cd38
6e78f43
 
bb2cd38
 
 
 
 
 
 
2d0e2b6
dd7320e
 
bb2cd38
 
 
 
 
 
 
 
 
 
 
 
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
# Asks for txt input, creates TTS and sound via AudioGen, plays it back
# Need to have paplay installed on client - live_demo.py

import os
import requests
import subprocess
from types import SimpleNamespace

def send_to_server(args):
    url = "http://192.168.88.209:5000"

    payload = {
        'text': args.text,
        'voice': args.voice,
        'soundscape': args.soundscape,
        'affective': True,
        'image': None,
        'video': None,
        'speed': 1.14,
        'native': None,
    }

    return requests.post(url, data=payload, files=[(args.text, open('_tmp.txt', 'rb'))])  # NONEs do not arrive to servers dict


args = SimpleNamespace()
args.voice = 'fr_FR_m-ailabs_bernard'  # 'en_US/m-ailabs_low#judy_bieber'
args.speed = 1.14
os.system('cls' if os.name == 'nt' else 'clear')
while True:
    _str = input("\n\n\n\nDescribe Any Sound: \n\n\n\n")
    args.soundscape = _str
    
    _str += 'Lorem ipsum dolor sit amet, consetetur elixir sed diam nonumy eirmod tempor invidunt labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Soutet clita kasd gubergren.'
    
    args.text = '_tmp.txt'  # input -> .txt (implementation thought for audiobooks in API)

    with open(args.text, 'w') as f:
        f.write(_str)
    if len(_str) >= 4:
        response = send_to_server(args)
        out_file = '_gen_.wav'#+ response.headers['suffix-file-type'].split('.')[-1]
        with open(out_file, 'wb') as f:
            f.write(response.content)
        subprocess.run(["paplay", out_file])
    else:
        print(f'__\n{_str}\n')