Skip to content

Commit 29026e9

Browse files
Ling Caoboltomli
authored andcommitted
Refined readmes, fixed comments
1 parent c47acf0 commit 29026e9

File tree

10 files changed

+339
-220
lines changed

10 files changed

+339
-220
lines changed

CustomVoice-API-Samples/CSharp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Usage: CustomVoice-API [APIKind] [action] [options]
4040
For more detailed usage, please enter: CustomVoice-API [APIKind]
4141
```
4242

43-
## Some parameters sets
43+
## Some parameter sets
4444

4545
- [HostURI](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/regions#speech-to-text-text-to-speech-and-translation)
4646

CustomVoice-API-Samples/Java/README.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
This project contains samples of HTTP-based Microsoft Neural Voice Long Audio APIs.
44

5-
## Build the samples
5+
## Before use
66

77
1. First, you must obtain a standard (not free) Speech service subscription key by following instructions in Microsoft Cognitive Services subscription.
88
1. Make sure that you have Maven installed. Under the directory with the pom file, run the command `mvn assembly:assembly` to Compile the executable jar package.
99
1. Run use this command: `java -jar target\CustomVoiceAPI-Java-1.0-SNAPSHOT.jar`. Related parameters, please refer to the following Usage.
1010

11-
#### usage
11+
## Usage
1212

1313
The following are the parameters required for the 5 executable commands:
1414
* Create Voice Synthesis task
1515
```
1616
[Required]
1717
-c,--create
18-
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
18+
-r,--region <arg> i.e. centralindia
1919
-s,--subscriptionkey <arg> The Speech service subscription key
2020
-n,--name <arg> The name of synthesis task
2121
-l,--locale <arg> The locale information like zh-CN/en-US
@@ -30,55 +30,67 @@ The following are the parameters required for the 5 executable commands:
3030
```
3131
[Required]
3232
-gv,--getvoice
33-
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
33+
-r,--region <arg> i.e. centralindia
3434
-s,--subscriptionkey <arg> The Speech service subscription key
3535
```
3636
* Get Voice Synthesis List
3737
```
3838
[Required]
3939
-gvs,--getvoicesynthesis
40-
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
40+
-r,--region <arg> i.e. centralindia
4141
-s,--subscriptionkey <arg> The Speech service subscription key
4242
[Optional]
4343
-sk,--skip <arg> The skip filter of the voice synthesis
4444
-st,--status <arg> The status filter of the voice synthesis query, could be NotStarted/Running/Succeeded/Failed
45-
-te,--timeend <arg> The timeend filter of the voice synthesis query, like 2020-05-01 15:26:21
45+
-ts,--timestart <arg> The timestart filter of the voice synthesis query, like 2020-05-01 12:00
46+
-te,--timeend <arg> The timeend filter of the voice synthesis query, like 2020-05-15
4647
-tp,--top <arg> The top filter of the voice synthesis query, should be a interger value
47-
-ts,--timestart <arg> The timestart filter of the voice synthesis query, like 2020-05-15 15:26:21
4848
```
4949
* Get Voice Synthesis by Id
5050
```
5151
[Required]
5252
-gvsi,--getvoicesynthesisbyid
53-
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
53+
-r,--region <arg> i.e. centralindia
5454
-s,--subscriptionkey <arg> The Speech service subscription key
5555
-vsi,--voicesynthesisid <arg> The id of the synthesis task
5656
```
5757
* Delete Voice Synthesis by Id
5858
```
5959
[Required]
6060
-dvs,--delete
61-
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
61+
-r,--region <arg> i.e. centralindia
6262
-s,--subscriptionkey <arg> The Speech service subscription key
6363
-vsi,--voicesynthesisid <arg> The id of the synthesis task
6464
```
6565

6666
## Note:
6767

6868
1. The input text file should be Unicode format with 'UTF-8-BOM' (you can check the text format with Notepad++), like the one en-US.txt, and shoule not contains lines more than 10000. Should contain at least 400 billable characters (1 en-US character stands for 1 billable characters and 1 zh-CN character stands for 2 billable characters). If billable characters number < 10000, please expect that the request probably be queued and will be done within 12 hours.If billable characters number > 10000, the request will be executed once where are available resource(not be queued).
69-
Billable character link: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/text-to-speech#pricing-note
69+
See [Billable character](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/text-to-speech#pricing-note).
7070
1. The id of the model (voice) could be acquired from the command "Get supported Voices".
71-
1. Available audio output formats are:
72-
"riff-8khz-16bit-mono-pcm",
73-
"riff-16khz-16bit-mono-pcm",
74-
"riff-24khz-16bit-mono-pcm",
75-
"riff-48khz-16bit-mono-pcm",
76-
"audio-16khz-32kbitrate-mono-mp3",
77-
"audio-16khz-64kbitrate-mono-mp3",
78-
"audio-16khz-128kbitrate-mono-mp3",
79-
"audio-24khz-48kbitrate-mono-mp3",
80-
"audio-24khz-96kbitrate-mono-mp3",
81-
"audio-24khz-160kbitrate-mono-mp3"
8271
1. Client for each subscription account is allowed to submit at most 5 requests to server per second, if hit the bar, client will get a 429 error code(too many requests).
8372
1. Server keep at most 120 requests in queue or running for each subscription accout, if hit the bar, should wait until some requests get completed before submit new ones.
8473
1. Server keep at most 20000 requests for each subscription account. If hit the bar, should delete some requests previously submitted before submit new ones.
74+
75+
## Some parameter sets
76+
77+
- [SupportedRegions](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/regions#speech-to-text-text-to-speech-and-translation) for the region in the host URL.
78+
79+
- [OutputFormat](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/rest-text-to-speech#audio-outputs)
80+
81+
# Contributing
82+
83+
We welcome contributions and are always looking for new SDKs, input, and
84+
suggestions. Feel free to file issues on the repo and we'll address them as we can. You can also learn more about how you can help on the [Contribution
85+
Rules & Guidelines](/CONTRIBUTING.md).
86+
87+
For questions, feedback, or suggestions about Microsoft Cognitive Services, feel free to reach out to us directly.
88+
89+
- [Cognitive Services UserVoice Forum](https://cognitive.uservoice.com)
90+
91+
# License
92+
93+
All Microsoft Cognitive Services SDKs and samples are licensed with the MIT License. For more details, see
94+
[LICENSE](/LICENSE.md).
95+
96+
Sample images are licensed separately, please refer to [LICENSE-IMAGE](/LICENSE-IMAGE.md).
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
* Speech Services API v3.0-beta1
3+
*/
4+
5+
package customvoice;
6+
7+
import java.io.File;
8+
import java.text.DateFormat;
9+
import java.text.SimpleDateFormat;
10+
import java.util.ArrayList;
11+
import java.util.Date;
12+
import java.util.List;
13+
import java.util.UUID;
14+
15+
import org.apache.commons.cli.CommandLine;
16+
import org.json.JSONArray;
17+
import org.json.JSONObject;
18+
19+
import customvoice.client.ApiClient;
20+
import customvoice.client.ApiException;
21+
import customvoice.client.Configuration;
22+
import customvoice.client.DateFormatHelper;
23+
import customvoice.model.Voice;
24+
import customvoice.model.VoiceSynthesis;
25+
26+
public class ApiHandler {
27+
public static void excuteApi(CommandLine cli) {
28+
String region = cli.getOptionValue("r");
29+
String hostPath = String.format(Configuration.HostUri, region);
30+
String subscriptionKey = cli.getOptionValue("subscriptionkey");
31+
32+
ApiClient apiClient = new ApiClient(hostPath);
33+
apiClient.setApiKey(subscriptionKey);
34+
VoiceSynthesisLib api = new VoiceSynthesisLib(apiClient);
35+
36+
try {
37+
if (cli.hasOption("create")) {
38+
String name = cli.getOptionValue("name");
39+
if (name == null) {
40+
System.out.println("Please enter the name of voice synthesis task");
41+
return;
42+
}
43+
44+
String description = cli.getOptionValue("description");
45+
if (description == null) {
46+
description = "";
47+
}
48+
49+
String locale = cli.getOptionValue("locale");
50+
if (locale == null) {
51+
System.out.println("Please enter the locale of the model voice synthesis task used");
52+
return;
53+
}
54+
55+
String modelList = cli.getOptionValue("modelidlist");
56+
if (modelList == null) {
57+
System.out
58+
.println("Please enter the model list of the voice synthesis task used, separated by ';'");
59+
return;
60+
}
61+
List<UUID> model = new ArrayList<UUID>();
62+
for (String id : modelList.split(";")) {
63+
model.add(UUID.fromString(id));
64+
}
65+
66+
String outputFormat = cli.getOptionValue("outputformat");
67+
if (outputFormat == null) {
68+
outputFormat = "riff-16khz-16bit-mono-pcm";
69+
}
70+
71+
String properties = "";
72+
if (cli.hasOption("concatenateresult")) {
73+
properties = "{\"ConcatenateResult\": \"true\"}";
74+
}
75+
76+
String scriptFile = cli.getOptionValue("scriptfile");
77+
if (scriptFile == null) {
78+
System.out.println("Please enter the script file path");
79+
return;
80+
}
81+
File script = new File(scriptFile);
82+
83+
String synthesisId = api.SubmitSynthesis(name, description, locale, model, outputFormat, properties,
84+
script);
85+
System.out.printf("Submit synthesis request successful , id: %s", synthesisId);
86+
return;
87+
} else if (cli.hasOption("getvoice")) {
88+
List<Voice> reslut = api.GetVoice();
89+
System.out.println(new JSONArray(reslut));
90+
} else if (cli.hasOption("getvoicesynthesis")) {
91+
String timeStarts = cli.getOptionValue("timestart");
92+
String timeEnds = cli.getOptionValue("timeend");
93+
String status = cli.getOptionValue("status");
94+
String skips = cli.getOptionValue("skip");
95+
int skip = -1;
96+
if (skips != null) {
97+
try {
98+
skip = Integer.parseInt(skips);
99+
if (skip < 0) {
100+
System.out.println(
101+
"Please enter a valid skip parameter, should be a ingeter greater or equals 0");
102+
return;
103+
}
104+
} catch (NumberFormatException e) {
105+
System.out.println(
106+
"Please enter a valid skip parameter, should be a ingeter greater or equals 0");
107+
return;
108+
}
109+
}
110+
int top = -1;
111+
String tops = cli.getOptionValue("top");
112+
if (tops != null) {
113+
try {
114+
top = Integer.parseInt(tops);
115+
if (top < 0) {
116+
System.out
117+
.println("Please enter a valid top parameter, should be a ingeter greater than 0");
118+
return;
119+
}
120+
} catch (NumberFormatException e) {
121+
System.out.println("Please enter a valid top parameter, should be a ingeter greater than 0");
122+
return;
123+
}
124+
}
125+
Date timeStart = null;
126+
if (timeStarts != null) {
127+
try {
128+
timeStart = DateFormatHelper.parseToDate(timeStarts);
129+
} catch (NumberFormatException e) {
130+
System.out.println("Please enter a valid timestart parameter, like 2020-05-01 12:00");
131+
return;
132+
}
133+
}
134+
Date timeEnd = null;
135+
if (timeEnds != null) {
136+
try {
137+
timeEnd = DateFormatHelper.parseToDate(timeEnds);
138+
} catch (NumberFormatException e) {
139+
System.out.println("Please enter a valid timeend parameter, like 2020-05-15");
140+
return;
141+
}
142+
}
143+
List<VoiceSynthesis> result = api.GetVoiceSynthesis(timeStart, timeEnd, status, skip, top);
144+
System.out.println(new JSONArray(result));
145+
} else if (cli.hasOption("getvoicesynthesisbyid")) {
146+
String voiceSynthesisId = cli.getOptionValue("voicesynthesisid");
147+
if (voiceSynthesisId == null) {
148+
System.out.println("Please enter Voice Synthesis Id");
149+
return;
150+
}
151+
VoiceSynthesis reslut = api.GetVoiceSynthesis(UUID.fromString(voiceSynthesisId));
152+
System.out.println(new JSONObject(reslut));
153+
} else if (cli.hasOption("delete")) {
154+
String voiceSynthesisId = cli.getOptionValue("voicesynthesisid");
155+
if (voiceSynthesisId == null) {
156+
System.out.println("Please enter Voice Synthesis Id");
157+
return;
158+
}
159+
api.DeleteSynthesis(UUID.fromString(voiceSynthesisId));
160+
System.out.printf("Delete successful, id : %s", voiceSynthesisId);
161+
} else {
162+
System.out.println("Please enter the action you need to perform");
163+
}
164+
} catch (Exception e) {
165+
System.out.println(
166+
"Request failed, wrong parameter or request timed out, please check the parameters and try again.");
167+
System.out.println("We got unexpected: " + e.getMessage());
168+
if (e instanceof ApiException) {
169+
System.out.println("Response body: " + ((ApiException) e).getResponseBody());
170+
}
171+
e.printStackTrace();
172+
return;
173+
}
174+
}
175+
}

0 commit comments

Comments
 (0)