Skip to content

Commit

Permalink
Refined readmes, fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ling Cao authored and boltomli committed May 18, 2020
1 parent c47acf0 commit 29026e9
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 220 deletions.
2 changes: 1 addition & 1 deletion CustomVoice-API-Samples/CSharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Usage: CustomVoice-API [APIKind] [action] [options]
For more detailed usage, please enter: CustomVoice-API [APIKind]
```

## Some parameters sets
## Some parameter sets

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

Expand Down
54 changes: 33 additions & 21 deletions CustomVoice-API-Samples/Java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

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

## Build the samples
## Before use

1. First, you must obtain a standard (not free) Speech service subscription key by following instructions in Microsoft Cognitive Services subscription.
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.
1. Run use this command: `java -jar target\CustomVoiceAPI-Java-1.0-SNAPSHOT.jar`. Related parameters, please refer to the following Usage.

#### usage
## Usage

The following are the parameters required for the 5 executable commands:
* Create Voice Synthesis task
```
[Required]
-c,--create
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
-r,--region <arg> i.e. centralindia
-s,--subscriptionkey <arg> The Speech service subscription key
-n,--name <arg> The name of synthesis task
-l,--locale <arg> The locale information like zh-CN/en-US
Expand All @@ -30,55 +30,67 @@ The following are the parameters required for the 5 executable commands:
```
[Required]
-gv,--getvoice
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
-r,--region <arg> i.e. centralindia
-s,--subscriptionkey <arg> The Speech service subscription key
```
* Get Voice Synthesis List
```
[Required]
-gvs,--getvoicesynthesis
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
-r,--region <arg> i.e. centralindia
-s,--subscriptionkey <arg> The Speech service subscription key
[Optional]
-sk,--skip <arg> The skip filter of the voice synthesis
-st,--status <arg> The status filter of the voice synthesis query, could be NotStarted/Running/Succeeded/Failed
-te,--timeend <arg> The timeend filter of the voice synthesis query, like 2020-05-01 15:26:21
-ts,--timestart <arg> The timestart filter of the voice synthesis query, like 2020-05-01 12:00
-te,--timeend <arg> The timeend filter of the voice synthesis query, like 2020-05-15
-tp,--top <arg> The top filter of the voice synthesis query, should be a interger value
-ts,--timestart <arg> The timestart filter of the voice synthesis query, like 2020-05-15 15:26:21
```
* Get Voice Synthesis by Id
```
[Required]
-gvsi,--getvoicesynthesisbyid
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
-r,--region <arg> i.e. centralindia
-s,--subscriptionkey <arg> The Speech service subscription key
-vsi,--voicesynthesisid <arg> The id of the synthesis task
```
* Delete Voice Synthesis by Id
```
[Required]
-dvs,--delete
-h,--hosturl <arg> i.e. https://centralindia.customvoice.api.speech.microsoft.com
-r,--region <arg> i.e. centralindia
-s,--subscriptionkey <arg> The Speech service subscription key
-vsi,--voicesynthesisid <arg> The id of the synthesis task
```

## Note:

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).
Billable character link: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/text-to-speech#pricing-note
See [Billable character](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/text-to-speech#pricing-note).
1. The id of the model (voice) could be acquired from the command "Get supported Voices".
1. Available audio output formats are:
"riff-8khz-16bit-mono-pcm",
"riff-16khz-16bit-mono-pcm",
"riff-24khz-16bit-mono-pcm",
"riff-48khz-16bit-mono-pcm",
"audio-16khz-32kbitrate-mono-mp3",
"audio-16khz-64kbitrate-mono-mp3",
"audio-16khz-128kbitrate-mono-mp3",
"audio-24khz-48kbitrate-mono-mp3",
"audio-24khz-96kbitrate-mono-mp3",
"audio-24khz-160kbitrate-mono-mp3"
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).
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.
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.

## Some parameter sets

- [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.

- [OutputFormat](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/rest-text-to-speech#audio-outputs)

# Contributing

We welcome contributions and are always looking for new SDKs, input, and
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
Rules & Guidelines](/CONTRIBUTING.md).

For questions, feedback, or suggestions about Microsoft Cognitive Services, feel free to reach out to us directly.

- [Cognitive Services UserVoice Forum](https://cognitive.uservoice.com)

# License

All Microsoft Cognitive Services SDKs and samples are licensed with the MIT License. For more details, see
[LICENSE](/LICENSE.md).

Sample images are licensed separately, please refer to [LICENSE-IMAGE](/LICENSE-IMAGE.md).
175 changes: 175 additions & 0 deletions CustomVoice-API-Samples/Java/src/main/java/customvoice/ApiHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* Speech Services API v3.0-beta1
*/

package customvoice;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.apache.commons.cli.CommandLine;
import org.json.JSONArray;
import org.json.JSONObject;

import customvoice.client.ApiClient;
import customvoice.client.ApiException;
import customvoice.client.Configuration;
import customvoice.client.DateFormatHelper;
import customvoice.model.Voice;
import customvoice.model.VoiceSynthesis;

public class ApiHandler {
public static void excuteApi(CommandLine cli) {
String region = cli.getOptionValue("r");
String hostPath = String.format(Configuration.HostUri, region);
String subscriptionKey = cli.getOptionValue("subscriptionkey");

ApiClient apiClient = new ApiClient(hostPath);
apiClient.setApiKey(subscriptionKey);
VoiceSynthesisLib api = new VoiceSynthesisLib(apiClient);

try {
if (cli.hasOption("create")) {
String name = cli.getOptionValue("name");
if (name == null) {
System.out.println("Please enter the name of voice synthesis task");
return;
}

String description = cli.getOptionValue("description");
if (description == null) {
description = "";
}

String locale = cli.getOptionValue("locale");
if (locale == null) {
System.out.println("Please enter the locale of the model voice synthesis task used");
return;
}

String modelList = cli.getOptionValue("modelidlist");
if (modelList == null) {
System.out
.println("Please enter the model list of the voice synthesis task used, separated by ';'");
return;
}
List<UUID> model = new ArrayList<UUID>();
for (String id : modelList.split(";")) {
model.add(UUID.fromString(id));
}

String outputFormat = cli.getOptionValue("outputformat");
if (outputFormat == null) {
outputFormat = "riff-16khz-16bit-mono-pcm";
}

String properties = "";
if (cli.hasOption("concatenateresult")) {
properties = "{\"ConcatenateResult\": \"true\"}";
}

String scriptFile = cli.getOptionValue("scriptfile");
if (scriptFile == null) {
System.out.println("Please enter the script file path");
return;
}
File script = new File(scriptFile);

String synthesisId = api.SubmitSynthesis(name, description, locale, model, outputFormat, properties,
script);
System.out.printf("Submit synthesis request successful , id: %s", synthesisId);
return;
} else if (cli.hasOption("getvoice")) {
List<Voice> reslut = api.GetVoice();
System.out.println(new JSONArray(reslut));
} else if (cli.hasOption("getvoicesynthesis")) {
String timeStarts = cli.getOptionValue("timestart");
String timeEnds = cli.getOptionValue("timeend");
String status = cli.getOptionValue("status");
String skips = cli.getOptionValue("skip");
int skip = -1;
if (skips != null) {
try {
skip = Integer.parseInt(skips);
if (skip < 0) {
System.out.println(
"Please enter a valid skip parameter, should be a ingeter greater or equals 0");
return;
}
} catch (NumberFormatException e) {
System.out.println(
"Please enter a valid skip parameter, should be a ingeter greater or equals 0");
return;
}
}
int top = -1;
String tops = cli.getOptionValue("top");
if (tops != null) {
try {
top = Integer.parseInt(tops);
if (top < 0) {
System.out
.println("Please enter a valid top parameter, should be a ingeter greater than 0");
return;
}
} catch (NumberFormatException e) {
System.out.println("Please enter a valid top parameter, should be a ingeter greater than 0");
return;
}
}
Date timeStart = null;
if (timeStarts != null) {
try {
timeStart = DateFormatHelper.parseToDate(timeStarts);
} catch (NumberFormatException e) {
System.out.println("Please enter a valid timestart parameter, like 2020-05-01 12:00");
return;
}
}
Date timeEnd = null;
if (timeEnds != null) {
try {
timeEnd = DateFormatHelper.parseToDate(timeEnds);
} catch (NumberFormatException e) {
System.out.println("Please enter a valid timeend parameter, like 2020-05-15");
return;
}
}
List<VoiceSynthesis> result = api.GetVoiceSynthesis(timeStart, timeEnd, status, skip, top);
System.out.println(new JSONArray(result));
} else if (cli.hasOption("getvoicesynthesisbyid")) {
String voiceSynthesisId = cli.getOptionValue("voicesynthesisid");
if (voiceSynthesisId == null) {
System.out.println("Please enter Voice Synthesis Id");
return;
}
VoiceSynthesis reslut = api.GetVoiceSynthesis(UUID.fromString(voiceSynthesisId));
System.out.println(new JSONObject(reslut));
} else if (cli.hasOption("delete")) {
String voiceSynthesisId = cli.getOptionValue("voicesynthesisid");
if (voiceSynthesisId == null) {
System.out.println("Please enter Voice Synthesis Id");
return;
}
api.DeleteSynthesis(UUID.fromString(voiceSynthesisId));
System.out.printf("Delete successful, id : %s", voiceSynthesisId);
} else {
System.out.println("Please enter the action you need to perform");
}
} catch (Exception e) {
System.out.println(
"Request failed, wrong parameter or request timed out, please check the parameters and try again.");
System.out.println("We got unexpected: " + e.getMessage());
if (e instanceof ApiException) {
System.out.println("Response body: " + ((ApiException) e).getResponseBody());
}
e.printStackTrace();
return;
}
}
}
Loading

0 comments on commit 29026e9

Please sign in to comment.