| import json, os, requests, warnings, wave |
| warnings.filterwarnings("ignore") |
|
|
|
|
| |
| |
| |
| |
| def tiro(text,voice,save='./',tiroalign = False): |
|
|
| |
| url = 'https://tts.tiro.is/v0/speech' |
| headers = {'Content-Type': 'application/json'} |
| |
|
|
|
|
| |
| payload_tts = { |
| "Engine": "standard", |
| "LanguageCode": "is-IS", |
| "OutputFormat": "pcm", |
| "SampleRate":"16000", |
| "Text": text, |
| "VoiceId": voice |
| } |
| |
| wname = save+voice+'.wav' |
| tts_data = requests.post(url, headers=headers, json=payload_tts, verify=False) |
| |
| with wave.open(wname,'wb') as f: |
| f.setnchannels(1) |
| f.setframerate(16000) |
| f.setsampwidth(2) |
| f.writeframes(tts_data.content) |
|
|
|
|
|
|
| |
| |
| |
| |
| payload_aln = { |
| "Engine": "standard", |
| "LanguageCode": "is-IS", |
| "OutputFormat": "json", |
| "SpeechMarkTypes": ["word"], |
| "Text": text, |
| "VoiceId": voice |
| } |
| aname = save+voice+'.json' |
| |
| if tiroalign: |
| aln_data = requests.post(url, headers=headers, json=payload_aln, verify=False) |
| with open(aname,'w') as f: |
| f.write('{"alignments": [') |
| f.write(aln_data.content.decode().replace('}\n{','},\n {')) |
| f.write(']}') |
|
|
|
|
| |
| return os.path.abspath(wname) |
|
|
|
|
| def grammatek(text,voice,save='./',UNUSED = False): |
|
|
| |
| url = 'https://api.grammatek.com/tts/v0/speech' |
| headers = {'Content-Type': 'application/json', |
| 'Accept': 'audio/mpeg,audio/x-wav,audio/ogg'} |
|
|
|
|
| |
| payload_tts = { |
| "Engine": "standard", |
| "LanguageCode": "is-IS", |
| "LexiconNames": [], |
| "OutputFormat": "pcm", |
| "SampleRate":"16000", |
| "SpeechMarkTypes": [ |
| "word" |
| ], |
| "Text": text, |
| "TextType": "text", |
| "VoiceId": voice |
| } |
|
|
| wname = save+voice+'.wav' |
| tts_data = requests.post(url, headers=headers, json=payload_tts, verify=False) |
| |
| with wave.open(wname,'wb') as f: |
| f.setnchannels(1) |
| f.setframerate(16000) |
| f.setsampwidth(2) |
| f.writeframes(tts_data.content) |
|
|
|
|
| |
| return os.path.abspath(wname) |
|
|
|
|