-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: Added command line option class + option to pass different l…
…ang code as argument (#1504) * added different language option for other than english * changed it to english * timestamp change * changed millisecond format to min:sec * Revert "timestamp change" This reverts commit df21c30. * removed indent issues * made requested changes
- Loading branch information
1 parent
d250d85
commit c3e846c
Showing
2 changed files
with
99 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
speech/snippets/src/main/java/com/example/speech/InfiniteStreamRecognizeOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.speech; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.DefaultParser; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
|
||
public class InfiniteStreamRecognizeOptions { | ||
String langCode = "en-US"; //by default english US | ||
|
||
/** Construct an InfiniteStreamRecognizeOptions class from command line flags. */ | ||
public static InfiniteStreamRecognizeOptions fromFlags(String[] args) { | ||
Options options = new Options(); | ||
options.addOption( | ||
Option.builder() | ||
.type(String.class) | ||
.longOpt("lang_code") | ||
.hasArg() | ||
.desc("Language code") | ||
.build()); | ||
|
||
CommandLineParser parser = new DefaultParser(); | ||
CommandLine commandLine; | ||
try { | ||
commandLine = parser.parse(options, args); | ||
InfiniteStreamRecognizeOptions res = new InfiniteStreamRecognizeOptions(); | ||
|
||
if (commandLine.hasOption("lang_code")) { | ||
res.langCode = commandLine.getOptionValue("lang_code"); | ||
} | ||
return res; | ||
} catch (ParseException e) { | ||
System.err.println(e.getMessage()); | ||
return null; | ||
} | ||
} | ||
|
||
} |