Skip to content

Commit 6197ab5

Browse files
authored
Merge pull request #120 from hepower/master
Update client to:
2 parents 74d8268 + 16fa6ea commit 6197ab5

File tree

7 files changed

+73
-25
lines changed

7 files changed

+73
-25
lines changed

CustomVoice-API-Samples/CSharp/CustomVoice-API/CustomVoiceAPI.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,15 @@ public void UpdateSynthesis(Guid id, string newName, string newDesc)
230230
VoiceAPIHelper.PatchVoiceSynthesis(VoiceSynthesisUpdate.Create(newName, newDesc), this.subscriptionKey, string.Format(CultureInfo.InvariantCulture, DeleteSynthesisUrl, id.ToString()));
231231
}
232232

233-
public async Task<Uri> CreateVoiceSynthesis(string name, string description, string locale, string inputTextPath, Guid modelId, bool concatenateResult)
233+
public async Task<Uri> CreateVoiceSynthesis(string name, string description, string locale, string outputFormat, string inputTextPath, IEnumerable<Guid> modelIds, bool concatenateResult)
234234
{
235235
Console.WriteLine("Creating batch synthesiss.");
236236
var properties = new Dictionary<string, string>();
237237
if (concatenateResult)
238238
{
239239
properties.Add("ConcatenateResult", "true");
240240
}
241-
var model = ModelIdentity.Create(modelId);
242-
var voiceSynthesisDefinition = VoiceSynthesisDefinition.Create(name, description, locale, model, properties);
241+
var voiceSynthesisDefinition = VoiceSynthesisDefinition.Create(name, description, locale, outputFormat, modelIds, properties);
243242
using (var submitResponse = VoiceAPIHelper.SubmitVoiceSynthesis(voiceSynthesisDefinition, inputTextPath, VoiceSynthesisUrl, this.subscriptionKey))
244243
{
245244
return await GetLocationFromPostResponseAsync(submitResponse).ConfigureAwait(false);

CustomVoice-API-Samples/CSharp/CustomVoice-API/Program.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,28 @@ private static async Task VoiceSynthsisAPIs()
127127
return;
128128
}
129129

130+
List<Guid> modelIds = new List<Guid>();
131+
modelIds.Add(voiceId);
132+
130133
// indicate if want concatenate the output waves with a single file or not.
131-
bool concatenateResult = true;
134+
bool concatenateResult = false;
135+
136+
string outputFormat = "riff-16khz-16bit-mono-pcm";
137+
/* Available output format:
138+
"riff-8khz-16bit-mono-pcm",
139+
"riff-16khz-16bit-mono-pcm",
140+
"riff-24khz-16bit-mono-pcm",
141+
"riff-48khz-16bit-mono-pcm",
142+
"audio-16khz-32kbitrate-mono-mp3",
143+
"audio-16khz-64kbitrate-mono-mp3",
144+
"audio-16khz-128kbitrate-mono-mp3",
145+
"audio-24khz-48kbitrate-mono-mp3",
146+
"audio-24khz-96kbitrate-mono-mp3",
147+
"audio-24khz-160kbitrate-mono-mp3",
148+
*/
132149

133150
// Submit a voice synthesis request and get a ID
134-
var synthesisLocation = await customVoiceAPI.CreateVoiceSynthesis(name, description, locale, localInputTextFile, voiceId, concatenateResult).ConfigureAwait(false);
151+
var synthesisLocation = await customVoiceAPI.CreateVoiceSynthesis(name, description, locale, outputFormat, localInputTextFile, modelIds, concatenateResult).ConfigureAwait(false);
135152
var synthesisId = new Guid(synthesisLocation.ToString().Split('/').LastOrDefault());
136153

137154
Console.WriteLine("Checking status.");
@@ -199,11 +216,11 @@ private static Guid GetVoiceId(CustomVoiceAPI api, string locale, string voiceNa
199216
Voice voice = null;
200217
if (publicVoice)
201218
{
202-
voice = voices.Where(m => m.Locale == locale && m.Name.Contains(voiceName) && m.IsPublicVoice).FirstOrDefault();
219+
voice = voices.Where(m => m.Locale == locale && m.Name.Contains(voiceName) && m.IsPublicVoice).OrderByDescending(m => m.Created).FirstOrDefault();
203220
}
204221
else
205222
{
206-
voice = voices.Where(m => m.Locale == locale && m.Name.Contains(voiceName)).FirstOrDefault();
223+
voice = voices.Where(m => m.Locale == locale && m.Name.Contains(voiceName)).OrderByDescending(m => m.Created).FirstOrDefault();
207224
}
208225
if (voice == null)
209226
{

CustomVoice-API-Samples/CSharp/CustomVoice-API/VoiceAPI/DTO/Voice.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ namespace Microsoft.SpeechServices.Cris.Http
1010
public sealed class Voice
1111
{
1212
[JsonConstructor]
13-
private Voice(Guid id, string name, string locale, string gender, bool isPublicVoice)
13+
private Voice(Guid id, string name, string description, string locale, string gender, bool isPublicVoice, DateTime created)
1414
{
1515
this.Id = id;
1616
this.Name = name;
17+
this.Description = description;
1718
this.Gender = gender;
1819
this.Locale = locale;
1920
this.IsPublicVoice = isPublicVoice;
21+
this.Created = created;
2022
}
2123

2224
public string Name { get; set; }
2325

26+
public string Description { get; set; }
27+
2428

2529
public string Locale { get; set; }
2630

@@ -31,5 +35,7 @@ private Voice(Guid id, string name, string locale, string gender, bool isPublicV
3135
public string Gender { get; set; }
3236

3337
public bool IsPublicVoice { get; set; }
38+
39+
public DateTime Created { get; set; }
3440
}
3541
}

CustomVoice-API-Samples/CSharp/CustomVoice-API/VoiceAPI/DTO/VoiceSynthesisDefinition.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ namespace Microsoft.SpeechServices.Cris.Http
99

1010
public sealed class VoiceSynthesisDefinition
1111
{
12-
private VoiceSynthesisDefinition(string name, string description, string locale, ModelIdentity model, IReadOnlyDictionary<string, string> properties)
12+
private VoiceSynthesisDefinition(string name, string description, string locale, string outputFormat, IEnumerable<Guid> models, IReadOnlyDictionary<string, string> properties)
1313
{
1414
this.Name = name;
1515
this.Description = description;
1616
this.Locale = locale;
17-
this.Model = model;
17+
this.OutputFormat = outputFormat;
18+
this.Models = models;
1819
this.Properties = properties;
1920
}
2021

@@ -26,18 +27,21 @@ private VoiceSynthesisDefinition(string name, string description, string locale,
2627

2728
public string Locale { get; set; }
2829

29-
public ModelIdentity Model { get; set; }
30+
public string OutputFormat { get; set; }
31+
32+
public IEnumerable<Guid> Models { get; set; }
3033

3134
public IReadOnlyDictionary<string, string> Properties { get; set; }
3235

3336
public static VoiceSynthesisDefinition Create(
3437
string name,
3538
string description,
3639
string locale,
37-
ModelIdentity model,
40+
string outputFormat,
41+
IEnumerable<Guid> models,
3842
IReadOnlyDictionary<string, string> properties)
3943
{
40-
return new VoiceSynthesisDefinition(name, description, locale, model, properties);
44+
return new VoiceSynthesisDefinition(name, description, locale, outputFormat, models, properties);
4145
}
4246
}
4347
}

CustomVoice-API-Samples/CSharp/CustomVoice-API/VoiceAPI/VoiceAPIHelper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,14 @@ public static HttpResponseMessage SubmitVoiceSynthesis(VoiceSynthesisDefinition
174174
content.Add(new StringContent(voiceSynthesisDefinition.Description), "description");
175175
}
176176

177-
content.Add(new StringContent(voiceSynthesisDefinition.Model.Id.ToString()), "model");
177+
content.Add(new StringContent(JsonConvert.SerializeObject(voiceSynthesisDefinition.Models)), "models");
178178
content.Add(new StringContent(voiceSynthesisDefinition.Locale), "locale");
179179

180+
if (!string.IsNullOrEmpty(voiceSynthesisDefinition.OutputFormat))
181+
{
182+
content.Add(new StringContent(voiceSynthesisDefinition.OutputFormat), "outputformat");
183+
}
184+
180185
if (voiceSynthesisDefinition.Properties != null)
181186
{
182187
content.Add(new StringContent(JsonConvert.SerializeObject(voiceSynthesisDefinition.Properties)), "properties");
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
1. Install Python2 from https://www.python.org/downloads/release/python-2716/
1+
1. Install Python from https://www.python.org/downloads/release/
22

33
Usage guide:
44

55
1.Check the help of the tool:
6-
C:\Python27amd64\python.exe voiceclient.py -h
6+
python voiceclient.py -h
77

88
2.Get available voice list:
9-
C:\Python27amd64\python.exe voiceclient.py --voices -region centralindia -key your_key_here
9+
python voiceclient.py --voices -region centralindia -key your_key_here
1010

1111
3.Submit a voice synthesis request:
12-
C:\Python27amd64\python.exe voiceclient.py --submit -region centralindia -key your_key_here-file zh-CN.txt -locale zh-CN -voiceId voice_id_here --concatenateResult
12+
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
1313

1414
Note:
1515
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.
1616
b.The voiceId should pick up from MS guys or get from step2 above.
17-
c.'concatenateResult' is a optional parameters, if not give, the output will be multiple wave files per each line.
17+
c Available audio output formats are:
18+
"riff-8khz-16bit-mono-pcm",
19+
"riff-16khz-16bit-mono-pcm",
20+
"riff-24khz-16bit-mono-pcm",
21+
"riff-48khz-16bit-mono-pcm",
22+
"audio-16khz-32kbitrate-mono-mp3",
23+
"audio-16khz-64kbitrate-mono-mp3",
24+
"audio-16khz-128kbitrate-mono-mp3",
25+
"audio-24khz-48kbitrate-mono-mp3",
26+
"audio-24khz-96kbitrate-mono-mp3",
27+
"audio-24khz-160kbitrate-mono-mp3",
28+
d.'concatenateResult' is a optional parameters, if not give, the output will be multiple wave files per each line.
1829

1930

2031

CustomVoice-API-Samples/Python/voiceclient.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
parser.add_argument('--submit', action="store_true", default=False, help='submit a synthesis request')
1717
parser.add_argument('--concatenateResult', action="store_true", default=False, help='If concatenate result in a single wave file')
1818
parser.add_argument('-file', action="store", dest="file", help='the input text file path')
19-
parser.add_argument('-voiceId', action="store", dest="voiceId", help='the id of the voice which used to synthesis')
19+
parser.add_argument('-voiceId', action="store", nargs='+', dest="voiceId", help='the id of the voice which used to synthesis')
2020
parser.add_argument('-locale', action="store", dest="locale", help='the locale information like zh-CN/en-US')
21+
parser.add_argument('-format', action="store", dest="format", default='riff-16khz-16bit-mono-pcm', help='the output audio format')
2122
parser.add_argument('-key', action="store", dest="key", required=True, help='the cris subscription key, like ff1eb62d06d34767bda0207acb1da7d7 ')
2223
parser.add_argument('-region', action="store", dest="region", required=True, help='the region information, could be centralindia, canadacentral or uksouth')
2324

2425
args = parser.parse_args()
2526

2627
baseAddress = 'https://%s.cris.ai/api/texttospeech/v3.0-beta1/' % args.region
2728

28-
2929
def getSubmittedSyntheses():
3030
response=requests.get(baseAddress+"voicesynthesis", headers={"Ocp-Apim-Subscription-Key":args.key}, verify=False)
3131
syntheses = json.loads(response.text)
@@ -43,8 +43,9 @@ def getVoices():
4343

4444

4545
def submitSynthesis():
46-
filename=ntpath.basename(args.file)
47-
data={'name': 'simple test', 'description': 'desc...', 'model': args.voiceId, 'locale': args.locale}
46+
filename=ntpath.basename(args.file)
47+
modelList = args.voiceId
48+
data={'name': 'simple test', 'description': 'desc...', 'models': json.dumps(modelList), 'locale': args.locale, 'outputformat': args.format}
4849
if args.concatenateResult:
4950
properties={'ConcatenateResult': 'true'}
5051
data['properties'] = json.dumps(properties)
@@ -57,19 +58,21 @@ def submitSynthesis():
5758
return id
5859
else:
5960
print("Submit synthesis request failed")
61+
print("response.status_code: %d" % response.status_code)
62+
print("response.text: %s" % response.text)
6063
return 0
6164

6265
if args.voices:
6366
voices = getVoices()
6467
print("There are %d voices available:" % len(voices))
6568
for voice in voices:
66-
print ("Name: %s, Id: %s, Locale: %s, Gender: %s, PublicVoice: %s" % (voice['name'], voice['id'], voice['locale'], voice['gender'], voice['isPublicVoice']))
69+
print ("Name: %s, Description: %s, Id: %s, Locale: %s, Gender: %s, PublicVoice: %s, Created: %s" % (voice['name'], voice['description'], voice['id'], voice['locale'], voice['gender'], voice['isPublicVoice'], voice['created']))
6770

6871
if args.syntheses:
6972
synthese = getSubmittedSyntheses()
7073
print("There are %d synthesis requests submitted:" % len(synthese))
7174
for synthesis in synthese:
72-
print synthesis['name']
75+
print (synthesis['name'])
7376

7477
if args.submit:
7578
id = submitSynthesis()
@@ -86,6 +89,9 @@ def submitSynthesis():
8689
f.write(r.content)
8790
print("Succeeded... Result file downloaded : " + filename)
8891
break
92+
elif synthesis['status'] == "Failed":
93+
print("Failed...")
94+
break
8995
elif synthesis['status'] == "Running":
9096
print("Running...")
9197
elif synthesis['status'] == "NotStarted":

0 commit comments

Comments
 (0)