Skip to content

Commit

Permalink
Add delete and synthesis command in python client tool. (#141)
Browse files Browse the repository at this point in the history
* Add delete and synthsis in python client tool.
  • Loading branch information
hepower authored and boltomli committed Oct 8, 2019
1 parent 5dfbfd7 commit f34faac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
18 changes: 12 additions & 6 deletions CustomVoice-API-Samples/Python/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ Usage guide:
1.Check the help of the tool:
python voiceclient.py -h

2.Get available voice list:
2.Get submitted voice synthesis list:
python voiceclient.py --syntheses -region centralindia -key your_key_here

3.Get available voice list:
python voiceclient.py --voices -region centralindia -key your_key_here

3.Submit a voice synthesis request:
4.Submit a voice synthesis request:
python voiceclient.py --submit -region centralindia -key your_key_here -file zh-CN.txt -locale zh-CN -voiceId voice_id_here -format riff-16khz-16bit-mono-pcm --concatenateResult

5.Delete submitted voice synthesis requests:
python voiceclient.py --delete -region centralindia -key your_key_here -synthesisId id1 id2 id3 id4

Note:
a.The input text file should be Unicode format with 'UTF-8-BOM' (you can check the text format with Notepad++), like the one zh-CN.txt, and should be more than 50 lines.
b.The voiceId should pick up from MS guys or get from step2 above.
c Available audio output formats are:
a. The input text file should be Unicode format with 'UTF-8-BOM' (you can check the text format with Notepad++), like the one zh-CN.txt, and should be more than 50 lines.
b. The voiceId should pick up from MS guys or get from step2 above.
c. Available audio output formats are:
"riff-8khz-16bit-mono-pcm",
"riff-16khz-16bit-mono-pcm",
"riff-24khz-16bit-mono-pcm",
Expand All @@ -25,7 +31,7 @@ c Available audio output formats are:
"audio-24khz-48kbitrate-mono-mp3",
"audio-24khz-96kbitrate-mono-mp3",
"audio-24khz-160kbitrate-mono-mp3",
d.'concatenateResult' is a optional parameters, if not give, the output will be multiple wave files per each line.
d. 'concatenateResult' is a optional parameters, if not give, the output will be multiple wave files per each line.



22 changes: 18 additions & 4 deletions CustomVoice-API-Samples/Python/voiceclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
parser.add_argument('--voices', action="store_true", default=False, help='print voice list')
parser.add_argument('--syntheses', action="store_true", default=False, help='print synthesis list')
parser.add_argument('--submit', action="store_true", default=False, help='submit a synthesis request')
parser.add_argument('--delete', action="store_true", default=False, help='delete a synthesis request')
parser.add_argument('--concatenateResult', action="store_true", default=False, help='If concatenate result in a single wave file')
parser.add_argument('-file', action="store", dest="file", help='the input text file path')
parser.add_argument('-file', action="store", dest="file", help='the input text script file path')
parser.add_argument('-voiceId', action="store", nargs='+', dest="voiceId", help='the id of the voice which used to synthesis')
parser.add_argument('-synthesisId', action="store", nargs='+', dest="synthesisId", help='the id of the voice synthesis which need to be deleted')
parser.add_argument('-locale', action="store", dest="locale", help='the locale information like zh-CN/en-US')
parser.add_argument('-format', action="store", dest="format", default='riff-16khz-16bit-mono-pcm', help='the output audio format')
parser.add_argument('-key', action="store", dest="key", required=True, help='the cris subscription key, like ff1eb62d06d34767bda0207acb1da7d7 ')
Expand All @@ -41,15 +43,24 @@ def getVoices():
voices = json.loads(response.text)
return voices

def deleteSynthesis(ids):
for id in ids:
print("delete voice synthesis %s " % id)
response = requests.delete(baseAddress+"voicesynthesis/"+id, headers={"Ocp-Apim-Subscription-Key":args.key}, verify=False)
if (response.status_code == 204):
print("delete successful")
else:
print("delete failed, response.status_code: %d, response.text: %s " % (response.status_code, response.text))

def submitSynthesis():
filename=ntpath.basename(args.file)
modelList = args.voiceId
data={'name': 'simple test', 'description': 'desc...', 'models': json.dumps(modelList), 'locale': args.locale, 'outputformat': args.format}
if args.concatenateResult:
properties={'ConcatenateResult': 'true'}
data['properties'] = json.dumps(properties)
files = {'script': (filename, open(args.file, 'rb'), 'text/plain')}
if args.file is not None:
scriptfilename=ntpath.basename(args.file)
files = {'script': (scriptfilename, open(args.file, 'rb'), 'text/plain')}
response = requests.post(baseAddress+"voicesynthesis", data, headers={"Ocp-Apim-Subscription-Key":args.key}, files=files, verify=False)
if response.status_code == 202:
location = response.headers['Operation-Location']
Expand All @@ -72,7 +83,10 @@ def submitSynthesis():
synthese = getSubmittedSyntheses()
print("There are %d synthesis requests submitted:" % len(synthese))
for synthesis in synthese:
print (synthesis['name'])
print ("ID : %s , Name : %s, Status : %s " % (synthesis['id'], synthesis['name'], synthesis['status']))

if args.delete:
deleteSynthesis(args.synthesisId)

if args.submit:
id = submitSynthesis()
Expand Down

0 comments on commit f34faac

Please sign in to comment.