(context, "EvalScreen");
111 | }, child: Text("go to eval screen")
112 | )
113 | ],
114 | ),
115 | ),
116 | );
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/http_samples/flutter_http_sample/pubspec.lock:
--------------------------------------------------------------------------------
1 | # Generated by pub
2 | # See https://dart.dev/tools/pub/glossary#lockfile
3 | packages:
4 | async:
5 | dependency: transitive
6 | description:
7 | name: async
8 | url: "https://pub.dartlang.org"
9 | source: hosted
10 | version: "2.8.2"
11 | boolean_selector:
12 | dependency: transitive
13 | description:
14 | name: boolean_selector
15 | url: "https://pub.dartlang.org"
16 | source: hosted
17 | version: "2.1.0"
18 | characters:
19 | dependency: transitive
20 | description:
21 | name: characters
22 | url: "https://pub.dartlang.org"
23 | source: hosted
24 | version: "1.2.0"
25 | charcode:
26 | dependency: transitive
27 | description:
28 | name: charcode
29 | url: "https://pub.dartlang.org"
30 | source: hosted
31 | version: "1.3.1"
32 | clock:
33 | dependency: transitive
34 | description:
35 | name: clock
36 | url: "https://pub.dartlang.org"
37 | source: hosted
38 | version: "1.1.0"
39 | collection:
40 | dependency: transitive
41 | description:
42 | name: collection
43 | url: "https://pub.dartlang.org"
44 | source: hosted
45 | version: "1.16.0"
46 | crypto:
47 | dependency: "direct dev"
48 | description:
49 | name: crypto
50 | url: "https://pub.dartlang.org"
51 | source: hosted
52 | version: "3.0.2"
53 | cupertino_icons:
54 | dependency: "direct main"
55 | description:
56 | name: cupertino_icons
57 | url: "https://pub.dartlang.org"
58 | source: hosted
59 | version: "1.0.5"
60 | fake_async:
61 | dependency: transitive
62 | description:
63 | name: fake_async
64 | url: "https://pub.dartlang.org"
65 | source: hosted
66 | version: "1.3.0"
67 | flutter:
68 | dependency: "direct main"
69 | description: flutter
70 | source: sdk
71 | version: "0.0.0"
72 | flutter_lints:
73 | dependency: "direct dev"
74 | description:
75 | name: flutter_lints
76 | url: "https://pub.dartlang.org"
77 | source: hosted
78 | version: "2.0.1"
79 | flutter_test:
80 | dependency: "direct dev"
81 | description: flutter
82 | source: sdk
83 | version: "0.0.0"
84 | http:
85 | dependency: "direct dev"
86 | description:
87 | name: http
88 | url: "https://pub.dartlang.org"
89 | source: hosted
90 | version: "0.13.5"
91 | http_parser:
92 | dependency: transitive
93 | description:
94 | name: http_parser
95 | url: "https://pub.dartlang.org"
96 | source: hosted
97 | version: "4.0.2"
98 | lints:
99 | dependency: transitive
100 | description:
101 | name: lints
102 | url: "https://pub.dartlang.org"
103 | source: hosted
104 | version: "2.0.1"
105 | matcher:
106 | dependency: transitive
107 | description:
108 | name: matcher
109 | url: "https://pub.dartlang.org"
110 | source: hosted
111 | version: "0.12.11"
112 | material_color_utilities:
113 | dependency: transitive
114 | description:
115 | name: material_color_utilities
116 | url: "https://pub.dartlang.org"
117 | source: hosted
118 | version: "0.1.4"
119 | meta:
120 | dependency: transitive
121 | description:
122 | name: meta
123 | url: "https://pub.dartlang.org"
124 | source: hosted
125 | version: "1.7.0"
126 | path:
127 | dependency: transitive
128 | description:
129 | name: path
130 | url: "https://pub.dartlang.org"
131 | source: hosted
132 | version: "1.8.1"
133 | sky_engine:
134 | dependency: transitive
135 | description: flutter
136 | source: sdk
137 | version: "0.0.99"
138 | source_span:
139 | dependency: transitive
140 | description:
141 | name: source_span
142 | url: "https://pub.dartlang.org"
143 | source: hosted
144 | version: "1.8.2"
145 | stack_trace:
146 | dependency: transitive
147 | description:
148 | name: stack_trace
149 | url: "https://pub.dartlang.org"
150 | source: hosted
151 | version: "1.10.0"
152 | stream_channel:
153 | dependency: transitive
154 | description:
155 | name: stream_channel
156 | url: "https://pub.dartlang.org"
157 | source: hosted
158 | version: "2.1.0"
159 | string_scanner:
160 | dependency: transitive
161 | description:
162 | name: string_scanner
163 | url: "https://pub.dartlang.org"
164 | source: hosted
165 | version: "1.1.0"
166 | term_glyph:
167 | dependency: transitive
168 | description:
169 | name: term_glyph
170 | url: "https://pub.dartlang.org"
171 | source: hosted
172 | version: "1.2.0"
173 | test_api:
174 | dependency: transitive
175 | description:
176 | name: test_api
177 | url: "https://pub.dartlang.org"
178 | source: hosted
179 | version: "0.4.9"
180 | typed_data:
181 | dependency: transitive
182 | description:
183 | name: typed_data
184 | url: "https://pub.dartlang.org"
185 | source: hosted
186 | version: "1.3.1"
187 | vector_math:
188 | dependency: transitive
189 | description:
190 | name: vector_math
191 | url: "https://pub.dartlang.org"
192 | source: hosted
193 | version: "2.1.2"
194 | sdks:
195 | dart: ">=2.17.1 <3.0.0"
196 |
--------------------------------------------------------------------------------
/http_samples/flutter_http_sample/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: flutter_http_sample
2 | description: A new Flutter project.
3 |
4 | # The following line prevents the package from being accidentally published to
5 | # pub.dev using `flutter pub publish`. This is preferred for private packages.
6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev
7 |
8 | # The following defines the version and build number for your application.
9 | # A version number is three numbers separated by dots, like 1.2.43
10 | # followed by an optional build number separated by a +.
11 | # Both the version and the builder number may be overridden in flutter
12 | # build by specifying --build-name and --build-number, respectively.
13 | # In Android, build-name is used as versionName while build-number used as versionCode.
14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16 | # Read more about iOS versioning at
17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18 | version: 1.0.0+1
19 |
20 | environment:
21 | sdk: ">=2.17.1 <3.0.0"
22 |
23 | # Dependencies specify other packages that your package needs in order to work.
24 | # To automatically upgrade your package dependencies to the latest versions
25 | # consider running `flutter pub upgrade --major-versions`. Alternatively,
26 | # dependencies can be manually updated by changing the version numbers below to
27 | # the latest version available on pub.dev. To see which dependencies have newer
28 | # versions available, run `flutter pub outdated`.
29 | dependencies:
30 | flutter:
31 | sdk: flutter
32 |
33 |
34 | # The following adds the Cupertino Icons font to your application.
35 | # Use with the CupertinoIcons class for iOS style icons.
36 | cupertino_icons: ^1.0.2
37 |
38 | dev_dependencies:
39 | flutter_test:
40 | sdk: flutter
41 |
42 | # The "flutter_lints" package below contains a set of recommended lints to
43 | # encourage good coding practices. The lint set provided by the package is
44 | # activated in the `analysis_options.yaml` file located at the root of your
45 | # package. See that file for information about deactivating specific lint
46 | # rules and activating additional ones.
47 | flutter_lints: ^2.0.0
48 |
49 | http: ^0.13.5
50 | crypto: ^3.0.2
51 |
52 | # For information on the generic Dart part of this file, see the
53 | # following page: https://dart.dev/tools/pub/pubspec
54 |
55 | # The following section is specific to Flutter packages.
56 | flutter:
57 |
58 | # The following line ensures that the Material Icons font is
59 | # included with your application, so that you can use the icons in
60 | # the material Icons class.
61 | uses-material-design: true
62 |
63 | assets:
64 | - assets/
65 | # To add assets to your application, add an assets section, like this:
66 | # assets:
67 | # - images/a_dot_burr.jpeg
68 | # - images/a_dot_ham.jpeg
69 |
70 | # An image asset can refer to one or more resolution-specific "variants", see
71 | # https://flutter.dev/assets-and-images/#resolution-aware
72 |
73 | # For details regarding adding assets from package dependencies, see
74 | # https://flutter.dev/assets-and-images/#from-packages
75 |
76 | # To add custom fonts to your application, add a fonts section here,
77 | # in this "flutter" section. Each entry in this list should have a
78 | # "family" key with the font family name, and a "fonts" key with a
79 | # list giving the asset and other descriptors for the font. For
80 | # example:
81 | # fonts:
82 | # - family: Schyler
83 | # fonts:
84 | # - asset: fonts/Schyler-Regular.ttf
85 | # - asset: fonts/Schyler-Italic.ttf
86 | # style: italic
87 | # - family: Trajan Pro
88 | # fonts:
89 | # - asset: fonts/TrajanPro.ttf
90 | # - asset: fonts/TrajanPro_Bold.ttf
91 | # weight: 700
92 | #
93 | # For details regarding fonts from package dependencies,
94 | # see https://flutter.dev/custom-fonts/#from-packages
95 |
--------------------------------------------------------------------------------
/http_samples/flutter_http_sample/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility in the flutter_test package. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'package:flutter/material.dart';
9 | import 'package:flutter_test/flutter_test.dart';
10 |
11 | import 'package:flutter_http_sample/main.dart';
12 |
13 | void main() {
14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15 | // Build our app and trigger a frame.
16 | await tester.pumpWidget(const MyApp());
17 |
18 | // Verify that our counter starts at 0.
19 | expect(find.text('0'), findsOneWidget);
20 | expect(find.text('1'), findsNothing);
21 |
22 | // Tap the '+' icon and trigger a frame.
23 | await tester.tap(find.byIcon(Icons.add));
24 | await tester.pump();
25 |
26 | // Verify that our counter has incremented.
27 | expect(find.text('0'), findsNothing);
28 | expect(find.text('1'), findsOneWidget);
29 | });
30 | }
31 |
--------------------------------------------------------------------------------
/http_samples/golang_http_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 |
3 | 1. Install Golang
4 | 2. Modify the appKey in sample.go
5 | 3. Modify the secretKey in sample.go
6 | 4. Change the coreType according to your needs.
7 | 5. Change the reference text according to your needs.
8 | 6. Change the audio path corresponding to the reference text.
9 | 7. Change the audio type corresponding to the audio file.
10 | 8. Run the following command:
11 | ```
12 | go run sample.go
13 | ```
--------------------------------------------------------------------------------
/http_samples/golang_http_sample/go.mod:
--------------------------------------------------------------------------------
1 | module golang_http_sample
2 |
3 | go 1.15
4 |
5 | require github.com/google/uuid v1.3.0
6 |
--------------------------------------------------------------------------------
/http_samples/golang_http_sample/sample.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "crypto/sha1"
6 | "fmt"
7 | "io"
8 | "io/ioutil"
9 | "log"
10 | "mime/multipart"
11 | "net/http"
12 | "os"
13 | "strconv"
14 | "time"
15 |
16 | "github.com/google/uuid"
17 | )
18 |
19 | func main() {
20 | appKey := "Insert your appKey here"
21 | secretKey := "Insert your secretKey here"
22 |
23 | baseURL := "https://api.speechsuper.com/"
24 |
25 | coreType := "word.eval.promax" // Change the coreType according to your needs.
26 | refText := "supermarket" // Change the reference text according to your needs.
27 | audioPath := "supermarket.wav" // Change the audio path corresponding to the reference text.
28 | audioType := "wav" // Change the audio type corresponding to the audio file.
29 | audioSampleRate := "16000"
30 | userId := "guest" // Required and customizable. This value is required when generating startSig
31 |
32 | url := baseURL + coreType
33 | method := "POST"
34 | payload := &bytes.Buffer{}
35 | writer := multipart.NewWriter(payload)
36 |
37 | timestamp := strconv.FormatInt(time.Now().Unix(), 10)
38 |
39 | connectData := []byte(appKey + timestamp + secretKey)
40 | startData := []byte(appKey + timestamp + userId + secretKey)
41 | connectSig := fmt.Sprintf("%x", sha1.Sum(connectData))
42 | startSig := fmt.Sprintf("%x", sha1.Sum(startData))
43 |
44 |
45 | // request param
46 | requestParam := `{"connect": {"cmd": "connect", "param": {"sdk": {"version": 16777472, "source": 9, "protocol": 2}, "app":{"applicationId":"` + appKey + `","sig":"` + connectSig + `","timestamp":"` + timestamp + `"}}}, "start": {"cmd": "start", "param": {"app":{"applicationId":"` + appKey + `","sig":"` + startSig + `","timestamp":"` + timestamp + `","userId":"` + userId + `"}, "audio": {"audioType": "` + audioType + `", "channel": 1, "sampleBytes": 2, "sampleRate":` + audioSampleRate + `}, "request": {"coreType": "` + coreType + `", "refText":"` + refText + `", "tokenId": "` + uuid.New().String() + `"}}}}`
47 | err := writer.WriteField("text", requestParam)
48 | if err != nil {
49 | log.Fatal(err)
50 | }
51 |
52 | // send audio
53 | part2, err := writer.CreateFormFile("audio", audioPath)
54 | if err != nil {
55 | log.Fatal(err)
56 | }
57 |
58 | file, err := os.Open(audioPath)
59 | if err != nil {
60 | log.Fatal(err)
61 | }
62 | defer file.Close()
63 | _, err = io.Copy(part2, file)
64 | if err != nil {
65 | log.Fatal(err)
66 | }
67 |
68 | err = writer.Close()
69 | if err != nil {
70 | fmt.Println(err)
71 | }
72 |
73 | client := &http.Client{}
74 | req, err := http.NewRequest(method, url, payload)
75 | if err != nil {
76 | log.Fatal(err)
77 | }
78 |
79 | req.Header.Set("Content-Type", writer.FormDataContentType())
80 | req.Header.Set("Request-Index", "0") // Request-Index is always 0
81 |
82 | res, err := client.Do(req)
83 | if err != nil {
84 | log.Fatal(err)
85 | }
86 |
87 | defer res.Body.Close()
88 | body, err := ioutil.ReadAll(res.Body)
89 | if err != nil {
90 | log.Fatal(err)
91 | }
92 |
93 | log.Printf("result===> %s", body)
94 | }
95 |
--------------------------------------------------------------------------------
/http_samples/golang_http_sample/supermarket.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/http_samples/golang_http_sample/supermarket.wav
--------------------------------------------------------------------------------
/http_samples/java_http_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 | - Modify the appKey in src\main\java\com\speechsuper\Sample.java
3 | - Modify the secretKey in src\main\java\com\speechsuper\Sample.java
4 | - Change the coreType according to your needs.
5 | - Change the reference text according to your needs.
6 | - Change the audio path corresponding to the reference text.
7 | - Change the audio type corresponding to the audio file.
8 |
9 | # Requirements
10 | - Java JDK 1.7+
11 | - Maven
12 |
13 | # Command lines
14 | - Compile:
15 | ```
16 | mvn clean compile
17 | ```
18 | - Run the `Sample` class:
19 | ```
20 | mvn compile exec:java -Dexec.mainClass="com.speechsuper.Sample"
21 | ```
--------------------------------------------------------------------------------
/http_samples/java_http_sample/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.speechsuper
6 | java_http_sample
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | sample
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 3.8.1
22 | test
23 |
24 |
25 | org.apache.httpcomponents
26 | httpclient
27 | 4.5.13
28 |
29 |
30 | org.apache.httpcomponents
31 | httpmime
32 | 4.5.13
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/http_samples/java_http_sample/src/main/java/com/speechsuper/Sample.java:
--------------------------------------------------------------------------------
1 | package com.speechsuper;
2 |
3 | import org.apache.commons.codec.binary.Hex;
4 | import org.apache.commons.codec.digest.DigestUtils;
5 | import org.apache.http.HttpEntity;
6 | import org.apache.http.client.ClientProtocolException;
7 | import org.apache.http.client.methods.CloseableHttpResponse;
8 | import org.apache.http.client.methods.HttpPost;
9 | import org.apache.http.entity.ContentType;
10 | import org.apache.http.entity.mime.MultipartEntityBuilder;
11 | import org.apache.http.entity.mime.content.FileBody;
12 | import org.apache.http.entity.mime.content.StringBody;
13 | import org.apache.http.impl.client.CloseableHttpClient;
14 | import org.apache.http.impl.client.DefaultHttpClient;
15 | import org.apache.http.util.EntityUtils;
16 |
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import java.security.MessageDigest;
21 |
22 | public class Sample {
23 |
24 | public static final String baseUrl = "https://api.speechsuper.com/";
25 | public static final String appKey = "Insert your appKey here";
26 | public static final String secretKey = "Insert your secretKey here";
27 |
28 | public static String HttpAPI(String audioPath, String audioType, String audioSampleRate, String refText, String coreType) {
29 | String url = baseUrl + coreType;
30 | //userId is randomly generated because the userId cannot be same during concurrent access
31 | String userId = getRandomString(5);
32 | String res = null;
33 | CloseableHttpClient httpclient = new DefaultHttpClient();
34 | String params = buildParam(appKey, secretKey, userId, audioType, audioSampleRate, refText, coreType);
35 | try {
36 |
37 | HttpPost httppost = new HttpPost(url);
38 | httppost.addHeader("Request-Index", "0");
39 |
40 | StringBody comment = new StringBody(params, ContentType.APPLICATION_JSON);
41 |
42 | FileBody bin = new FileBody(new File(audioPath));
43 | HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("text", comment).addPart("audio", bin).build();
44 | httppost.setEntity(reqEntity);
45 |
46 | CloseableHttpResponse response = httpclient.execute(httppost);
47 |
48 | try {
49 | HttpEntity resEntity = response.getEntity();
50 | if (resEntity != null) {
51 | res = EntityUtils.toString(resEntity, "UTF-8");
52 | }
53 | } finally {
54 | response.close();
55 | }
56 | } catch (ClientProtocolException e) {
57 | e.printStackTrace();
58 | } catch (IOException e) {
59 | e.printStackTrace();
60 | } finally {
61 | try {
62 | httpclient.close();
63 | } catch (IOException e) {
64 | e.printStackTrace();
65 | }
66 | }
67 | return res;
68 | }
69 |
70 | private static String buildParam(String appkey, String secretKey, String userId, String audioType, String audioSampleRate, String refText, String coreType) {
71 |
72 | MessageDigest digest = DigestUtils.getSha1Digest();
73 |
74 | long timeReqMillis = System.currentTimeMillis();
75 | String connectSigStr = appkey + timeReqMillis + secretKey;
76 | String connectSig = Hex.encodeHexString(digest.digest(connectSigStr.getBytes()));
77 |
78 | long timeStartMillis = System.currentTimeMillis();
79 | String startSigStr = appkey + timeStartMillis + userId + secretKey;
80 | String startSig = Hex.encodeHexString(digest.digest(startSigStr.getBytes()));
81 | //request param
82 | String params = "{"
83 | + "\"connect\":{"
84 | + "\"cmd\":\"connect\","
85 | + "\"param\":{"
86 | + "\"sdk\":{"
87 | + "\"protocol\":2,"
88 | + "\"version\":16777472,"
89 | + "\"source\":9"
90 | + "},"
91 | + "\"app\":{"
92 | + "\"applicationId\":\"" + appkey + "\","
93 | + "\"sig\":\"" + connectSig + "\","
94 | + "\"timestamp\":\"" + timeReqMillis + "\""
95 | + "}"
96 | + "}"
97 | + "},"
98 | + "\"start\":{"
99 | + "\"cmd\":\"start\","
100 | + "\"param\":{"
101 | + "\"app\":{"
102 | + "\"applicationId\":\"" + appkey + "\","
103 | + "\"timestamp\":\"" + timeStartMillis + "\","
104 | + "\"sig\":\"" + startSig + "\","
105 | + "\"userId\":\"" + userId + "\""
106 | + "},"
107 | + "\"audio\":{"
108 | + "\"sampleBytes\":2,"
109 | + "\"channel\":1,"
110 | + "\"sampleRate\":" + audioSampleRate + ","
111 | + "\"audioType\":\"" + audioType + "\""
112 | + "},"
113 | + "\"request\":{"
114 | + "\"tokenId\":\"tokenId\","
115 | + "\"refText\":\"" + refText + "\","
116 | + "\"coreType\":\"" + coreType + "\""
117 | + "}"
118 | + "}"
119 | + "}"
120 | + "}";
121 | return params;
122 | }
123 |
124 |
125 | private static int getRandom(int count) {
126 | return (int) Math.round(Math.random() * (count));
127 | }
128 |
129 | private static String charString = "abcdefghijklmnopqrstuvwxyz123456789";
130 |
131 | private static String getRandomString(int length) {
132 | StringBuffer sb = new StringBuffer();
133 | int len = charString.length();
134 | for (int i = 0; i < length; i++) {
135 | sb.append(charString.charAt(getRandom(len - 1)));
136 | }
137 | return sb.toString();
138 | }
139 |
140 | public static void main(String[] args) {
141 | String coreType = "word.eval.promax"; // Change the coreType according to your needs.
142 | String refText = "supermarket"; // Change the reference text according to your needs.
143 | String audioPath = "supermarket.wav"; // Change the audio path corresponding to the reference text.
144 | String audioType = "wav"; // Change the audio type corresponding to the audio file.
145 | String audioSampleRate = "16000";
146 | String result = HttpAPI(audioPath, audioType, audioSampleRate, refText, coreType);
147 | System.out.println("result===>" + result);
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/http_samples/java_http_sample/src/test/java/com/speechsuper/SampleTest.java:
--------------------------------------------------------------------------------
1 | package com.speechsuper;
2 |
3 | import junit.framework.Test;
4 | import junit.framework.TestCase;
5 | import junit.framework.TestSuite;
6 |
7 | /**
8 | * Unit test for simple Sample.
9 | */
10 | public class SampleTest
11 | extends TestCase
12 | {
13 | /**
14 | * Create the test case
15 | *
16 | * @param testName name of the test case
17 | */
18 | public SampleTest( String testName )
19 | {
20 | super( testName );
21 | }
22 |
23 | /**
24 | * @return the suite of tests being tested
25 | */
26 | public static Test suite()
27 | {
28 | return new TestSuite( SampleTest.class );
29 | }
30 |
31 | /**
32 | * Rigourous Test :-)
33 | */
34 | public void testSample()
35 | {
36 | assertTrue( true );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/http_samples/java_http_sample/supermarket.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/http_samples/java_http_sample/supermarket.wav
--------------------------------------------------------------------------------
/http_samples/javascript_http_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 |
3 | 1. Modify the appKey in sample.html
4 | 2. Modify the secretKey in sample.html
5 | 3. Change the coreType according to your needs.
6 | 5. Change the reference text according to your needs.
7 | 6. Select the audio corresponding to the reference text.
8 | 7. Change the audio type corresponding to the audio file.
9 | 8. Double click sample.html
--------------------------------------------------------------------------------
/http_samples/javascript_http_sample/sample.html:
--------------------------------------------------------------------------------
1 |
2 | -----------javascript http sample-----------
3 |
14 |
15 |
--------------------------------------------------------------------------------
/http_samples/javascript_http_sample/sha.js:
--------------------------------------------------------------------------------
1 | /*
2 | A JavaScript implementation of the SHA family of hashes, as
3 | defined in FIPS PUB 180-2 as well as the corresponding HMAC implementation
4 | as defined in FIPS PUB 198a
5 |
6 | Copyright Brian Turek 2008-2015
7 | Distributed under the BSD License
8 | See http://caligatio.github.com/jsSHA/ for more information
9 |
10 | Several functions taken from Paul Johnston
11 | */
12 | 'use strict';(function(U){function z(a,b,c){var e=0,f=[0],k="",h=null,k=c||"UTF8";if("UTF8"!==k&&"UTF16BE"!==k&&"UTF16LE"!==k)throw"encoding must be UTF8, UTF16BE, or UTF16LE";if("HEX"===b){if(0!==a.length%2)throw"srcString of HEX type must be in byte increments";h=D(a);e=h.binLen;f=h.value}else if("TEXT"===b||"ASCII"===b)h=L(a,k),e=h.binLen,f=h.value;else if("B64"===b)h=M(a),e=h.binLen,f=h.value;else if("BYTES"===b)h=N(a),e=h.binLen,f=h.value;else throw"inputFormat must be HEX, TEXT, ASCII, B64, or BYTES";
13 | this.getHash=function(a,b,c,k){var h=null,d=f.slice(),n=e,m;3===arguments.length?"number"!==typeof c&&(k=c,c=1):2===arguments.length&&(c=1);if(c!==parseInt(c,10)||1>c)throw"numRounds must a integer >= 1";switch(b){case "HEX":h=O;break;case "B64":h=P;break;case "BYTES":h=Q;break;default:throw"format must be HEX, B64, or BYTES";}if("SHA-1"===a)for(m=0;mm/8){for(;d.length<=b;)d.push(0);d[b]&=4294967040}for(n=0;n<=b;n+=1)r[n]=d[n]^
16 | 909522486,u[n]=d[n]^1549556828;c="SHA-1"===c?A(u.concat(A(r.concat(f),a+e)),a+t):w(u.concat(w(r.concat(f),a+e,c)),a+t,c);return h(c,R(q))}}function q(a,b){this.a=a;this.b=b}function L(a,b){var c=[],e,f=[],k=0,h,p,q;if("UTF8"===b)for(h=0;he?f.push(e):2048>e?(f.push(192|e>>>6),f.push(128|e&63)):55296>e||57344<=e?f.push(224|e>>>12,128|e>>>6&63,128|e&63):(h+=1,e=65536+((e&1023)<<10|a.charCodeAt(h)&1023),f.push(240|e>>>18,128|e>>>12&63,128|e>>>6&63,128|e&63)),
17 | p=0;p>>2;c.length<=q;)c.push(0);c[q]|=f[p]<<24-k%4*8;k+=1}else if("UTF16BE"===b||"UTF16LE"===b)for(h=0;h>8);for(q=k>>>2;c.length<=q;)c.push(0);c[q]|=e<<16-k%4*8;k+=2}return{value:c,binLen:8*k}}function D(a){var b=[],c=a.length,e,f,k;if(0!==c%2)throw"String of HEX type must be in byte increments";for(e=0;e>>3;b.length<=k;)b.push(0);b[e>>>3]|=f<<24-e%8*4}return{value:b,binLen:4*c}}function N(a){var b=[],c,e,f;for(e=0;e>>2,b.length<=f&&b.push(0),b[f]|=c<<24-e%4*8;return{value:b,binLen:8*a.length}}function M(a){var b=[],c=0,e,f,k,h,p;if(-1===a.search(/^[a-zA-Z0-9=+\/]+$/))throw"Invalid character in base-64 string";f=a.indexOf("=");a=a.replace(/\=/g,"");if(-1!==f&&f>>2;b.length<=e;)b.push(0);b[e]|=(h>>>16-8*k&255)<<24-c%4*8;c+=1}}return{value:b,binLen:8*c}}function O(a,b){var c="",e=4*a.length,f,k;for(f=0;f>>2]>>>8*(3-f%4),c+="0123456789abcdef".charAt(k>>>4&15)+"0123456789abcdef".charAt(k&15);return b.outputUpper?c.toUpperCase():c}function P(a,b){var c="",e=4*a.length,f,k,h;for(f=0;f>>2,k=a.length<=h?0:a[h],h=f+2>>>2,h=a.length<=h?0:a[h],h=(a[f>>>2]>>>8*(3-f%4)&255)<<16|(k>>>8*(3-(f+1)%4)&255)<<8|h>>>8*(3-(f+2)%4)&255,k=0;4>k;k+=1)c=8*f+6*k<=32*a.length?c+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(h>>>6*(3-k)&63):c+b.b64Pad;return c}function Q(a){var b="",c=4*a.length,e,f;for(e=0;e>>2]>>>8*(3-e%4)&255,b+=String.fromCharCode(f);return b}function R(a){var b={outputUpper:!1,b64Pad:"="};try{a.hasOwnProperty("outputUpper")&&
21 | (b.outputUpper=a.outputUpper),a.hasOwnProperty("b64Pad")&&(b.b64Pad=a.b64Pad)}catch(c){}if("boolean"!==typeof b.outputUpper)throw"Invalid outputUpper formatting option";if("string"!==typeof b.b64Pad)throw"Invalid b64Pad formatting option";return b}function x(a,b){return a<>>32-b}function r(a,b){return a>>>b|a<<32-b}function u(a,b){var c=null,c=new q(a.a,a.b);return c=32>=b?new q(c.a>>>b|c.b<<32-b&4294967295,c.b>>>b|c.a<<32-b&4294967295):new q(c.b>>>b-32|c.a<<64-b&4294967295,c.a>>>b-32|c.b<<64-
22 | b&4294967295)}function S(a,b){var c=null;return c=32>=b?new q(a.a>>>b,a.b>>>b|a.a<<32-b&4294967295):new q(0,a.a>>>b-32)}function V(a,b,c){return a&b^~a&c}function W(a,b,c){return new q(a.a&b.a^~a.a&c.a,a.b&b.b^~a.b&c.b)}function T(a,b,c){return a&b^a&c^b&c}function X(a,b,c){return new q(a.a&b.a^a.a&c.a^b.a&c.a,a.b&b.b^a.b&c.b^b.b&c.b)}function Y(a){return r(a,2)^r(a,13)^r(a,22)}function Z(a){var b=u(a,28),c=u(a,34);a=u(a,39);return new q(b.a^c.a^a.a,b.b^c.b^a.b)}function $(a){return r(a,6)^r(a,11)^
23 | r(a,25)}function aa(a){var b=u(a,14),c=u(a,18);a=u(a,41);return new q(b.a^c.a^a.a,b.b^c.b^a.b)}function ba(a){return r(a,7)^r(a,18)^a>>>3}function ca(a){var b=u(a,1),c=u(a,8);a=S(a,7);return new q(b.a^c.a^a.a,b.b^c.b^a.b)}function da(a){return r(a,17)^r(a,19)^a>>>10}function ea(a){var b=u(a,19),c=u(a,61);a=S(a,6);return new q(b.a^c.a^a.a,b.b^c.b^a.b)}function C(a,b){var c=(a&65535)+(b&65535);return((a>>>16)+(b>>>16)+(c>>>16)&65535)<<16|c&65535}function fa(a,b,c,e){var f=(a&65535)+(b&65535)+(c&65535)+
24 | (e&65535);return((a>>>16)+(b>>>16)+(c>>>16)+(e>>>16)+(f>>>16)&65535)<<16|f&65535}function E(a,b,c,e,f){var k=(a&65535)+(b&65535)+(c&65535)+(e&65535)+(f&65535);return((a>>>16)+(b>>>16)+(c>>>16)+(e>>>16)+(f>>>16)+(k>>>16)&65535)<<16|k&65535}function ga(a,b){var c,e,f;c=(a.b&65535)+(b.b&65535);e=(a.b>>>16)+(b.b>>>16)+(c>>>16);f=(e&65535)<<16|c&65535;c=(a.a&65535)+(b.a&65535)+(e>>>16);e=(a.a>>>16)+(b.a>>>16)+(c>>>16);return new q((e&65535)<<16|c&65535,f)}function ha(a,b,c,e){var f,k,h;f=(a.b&65535)+(b.b&
25 | 65535)+(c.b&65535)+(e.b&65535);k=(a.b>>>16)+(b.b>>>16)+(c.b>>>16)+(e.b>>>16)+(f>>>16);h=(k&65535)<<16|f&65535;f=(a.a&65535)+(b.a&65535)+(c.a&65535)+(e.a&65535)+(k>>>16);k=(a.a>>>16)+(b.a>>>16)+(c.a>>>16)+(e.a>>>16)+(f>>>16);return new q((k&65535)<<16|f&65535,h)}function ia(a,b,c,e,f){var k,h,p;k=(a.b&65535)+(b.b&65535)+(c.b&65535)+(e.b&65535)+(f.b&65535);h=(a.b>>>16)+(b.b>>>16)+(c.b>>>16)+(e.b>>>16)+(f.b>>>16)+(k>>>16);p=(h&65535)<<16|k&65535;k=(a.a&65535)+(b.a&65535)+(c.a&65535)+(e.a&65535)+(f.a&
26 | 65535)+(h>>>16);h=(a.a>>>16)+(b.a>>>16)+(c.a>>>16)+(e.a>>>16)+(f.a>>>16)+(k>>>16);return new q((h&65535)<<16|k&65535,p)}function A(a,b){var c=[],e,f,k,h,p,q,r,s,u,d=[1732584193,4023233417,2562383102,271733878,3285377520];for(e=(b+65>>>9<<4)+15;a.length<=e;)a.push(0);a[b>>>5]|=128<<24-b%32;a[e]=b;u=a.length;for(r=0;rs;s+=1)c[s]=16>s?a[s+r]:x(c[s-3]^c[s-8]^c[s-14]^c[s-16],1),q=20>s?E(x(e,5),f&k^~f&h,p,1518500249,c[s]):40>s?E(x(e,5),f^k^h,p,1859775393,
27 | c[s]):60>s?E(x(e,5),T(f,k,h),p,2400959708,c[s]):E(x(e,5),f^k^h,p,3395469782,c[s]),p=h,h=k,k=x(f,30),f=e,e=q;d[0]=C(e,d[0]);d[1]=C(f,d[1]);d[2]=C(k,d[2]);d[3]=C(h,d[3]);d[4]=C(p,d[4])}return d}function w(a,b,c){var e,f,k,h,p,r,u,s,y,d,n,m,t,w,x,v,z,A,F,G,H,I,J,K,g,B=[],D,l=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,
28 | 1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];d=[3238371032,914150663,812702999,4144912697,4290775857,
29 | 1750603025,1694076839,3204075428];f=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];if("SHA-224"===c||"SHA-256"===c)n=64,e=(b+65>>>9<<4)+15,w=16,x=1,g=Number,v=C,z=fa,A=E,F=ba,G=da,H=Y,I=$,K=T,J=V,d="SHA-224"===c?d:f;else if("SHA-384"===c||"SHA-512"===c)n=80,e=(b+128>>>10<<5)+31,w=32,x=2,g=q,v=ga,z=ha,A=ia,F=ca,G=ea,H=Z,I=aa,K=X,J=W,l=[new g(l[0],3609767458),new g(l[1],602891725),new g(l[2],3964484399),new g(l[3],2173295548),new g(l[4],4081628472),new g(l[5],
30 | 3053834265),new g(l[6],2937671579),new g(l[7],3664609560),new g(l[8],2734883394),new g(l[9],1164996542),new g(l[10],1323610764),new g(l[11],3590304994),new g(l[12],4068182383),new g(l[13],991336113),new g(l[14],633803317),new g(l[15],3479774868),new g(l[16],2666613458),new g(l[17],944711139),new g(l[18],2341262773),new g(l[19],2007800933),new g(l[20],1495990901),new g(l[21],1856431235),new g(l[22],3175218132),new g(l[23],2198950837),new g(l[24],3999719339),new g(l[25],766784016),new g(l[26],2566594879),
31 | new g(l[27],3203337956),new g(l[28],1034457026),new g(l[29],2466948901),new g(l[30],3758326383),new g(l[31],168717936),new g(l[32],1188179964),new g(l[33],1546045734),new g(l[34],1522805485),new g(l[35],2643833823),new g(l[36],2343527390),new g(l[37],1014477480),new g(l[38],1206759142),new g(l[39],344077627),new g(l[40],1290863460),new g(l[41],3158454273),new g(l[42],3505952657),new g(l[43],106217008),new g(l[44],3606008344),new g(l[45],1432725776),new g(l[46],1467031594),new g(l[47],851169720),new g(l[48],
32 | 3100823752),new g(l[49],1363258195),new g(l[50],3750685593),new g(l[51],3785050280),new g(l[52],3318307427),new g(l[53],3812723403),new g(l[54],2003034995),new g(l[55],3602036899),new g(l[56],1575990012),new g(l[57],1125592928),new g(l[58],2716904306),new g(l[59],442776044),new g(l[60],593698344),new g(l[61],3733110249),new g(l[62],2999351573),new g(l[63],3815920427),new g(3391569614,3928383900),new g(3515267271,566280711),new g(3940187606,3454069534),new g(4118630271,4000239992),new g(116418474,
33 | 1914138554),new g(174292421,2731055270),new g(289380356,3203993006),new g(460393269,320620315),new g(685471733,587496836),new g(852142971,1086792851),new g(1017036298,365543100),new g(1126000580,2618297676),new g(1288033470,3409855158),new g(1501505948,4234509866),new g(1607167915,987167468),new g(1816402316,1246189591)],d="SHA-384"===c?[new g(3418070365,d[0]),new g(1654270250,d[1]),new g(2438529370,d[2]),new g(355462360,d[3]),new g(1731405415,d[4]),new g(41048885895,d[5]),new g(3675008525,d[6]),
34 | new g(1203062813,d[7])]:[new g(f[0],4089235720),new g(f[1],2227873595),new g(f[2],4271175723),new g(f[3],1595750129),new g(f[4],2917565137),new g(f[5],725511199),new g(f[6],4215389547),new g(f[7],327033209)];else throw"Unexpected error in SHA-2 implementation";for(;a.length<=e;)a.push(0);a[b>>>5]|=128<<24-b%32;a[e]=b;D=a.length;for(m=0;mt?(y=t*x+m,s=a.length<=y?0:a[y],y=a.length<=y+1?0:a[y+1],B[t]=new g(s,y)):B[t]=
35 | z(G(B[t-2]),B[t-7],F(B[t-15]),B[t-16]),s=A(u,I(h),J(h,p,r),l[t],B[t]),y=v(H(b),K(b,e,f)),u=r,r=p,p=h,h=v(k,s),k=f,f=e,e=b,b=v(s,y);d[0]=v(b,d[0]);d[1]=v(e,d[1]);d[2]=v(f,d[2]);d[3]=v(k,d[3]);d[4]=v(h,d[4]);d[5]=v(p,d[5]);d[6]=v(r,d[6]);d[7]=v(u,d[7])}if("SHA-224"===c)a=[d[0],d[1],d[2],d[3],d[4],d[5],d[6]];else if("SHA-256"===c)a=d;else if("SHA-384"===c)a=[d[0].a,d[0].b,d[1].a,d[1].b,d[2].a,d[2].b,d[3].a,d[3].b,d[4].a,d[4].b,d[5].a,d[5].b];else if("SHA-512"===c)a=[d[0].a,d[0].b,d[1].a,d[1].b,d[2].a,
36 | d[2].b,d[3].a,d[3].b,d[4].a,d[4].b,d[5].a,d[5].b,d[6].a,d[6].b,d[7].a,d[7].b];else throw"Unexpected error in SHA-2 implementation";return a}"function"===typeof define&&define.amd?define(function(){return z}):"undefined"!==typeof exports?"undefined"!==typeof module&&module.exports?module.exports=exports=z:exports=z:U.jsSHA=z})(this);
37 |
--------------------------------------------------------------------------------
/http_samples/javascript_http_sample/supermarket.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/http_samples/javascript_http_sample/supermarket.wav
--------------------------------------------------------------------------------
/http_samples/nodejs_http_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 | - Modify the appKey in main.js
3 | - Modify the secretKey in main.js
4 | - Change the coreType according to your needs.
5 | - Change the reference text according to your needs.
6 | - Change the audio path corresponding to the reference text.
7 | - Change the audio type corresponding to the audio file.
8 |
9 |
10 | # Command lines
11 | - Run the following command:
12 | ```
13 | npm install
14 | npm run start
15 | ```
--------------------------------------------------------------------------------
/http_samples/nodejs_http_sample/main.js:
--------------------------------------------------------------------------------
1 |
2 | import {createHash} from 'crypto';
3 | import * as fs from 'fs/promises';
4 | import FormData from 'form-data';
5 |
6 | const appKey = "Insert your appKey here";
7 | const secretKey = "Insert your secretKey here";
8 | const userId = "uid";
9 |
10 | const baseHOST = "api.speechsuper.com";
11 |
12 | const coreType = "word.eval.promax"; // Change the coreType according to your needs.
13 | const refText = "supermarket"; // Change the reference text according to your needs.
14 | const audioPath = "supermarket.wav"; // Change the audio path corresponding to the reference text.
15 | const audioType = "wav"; // Change the audio type corresponding to the audio file.
16 | const audioSampleRate = "16000";
17 |
18 | async function doEval(userId, audioType, sampleRate, requestParams, audioPath) {
19 | const coreType = requestParams['coreType'];
20 |
21 | let encrypt = function(content) {
22 | let hash = createHash("sha1");
23 | hash.update(content);
24 | return hash.digest('hex');
25 | }
26 |
27 | let getConnectSig = function () {
28 | var timestamp = new Date().getTime().toString();
29 | var sig = encrypt(appKey + timestamp + secretKey);
30 | return { sig: sig, timestamp: timestamp };
31 | }
32 | let getStartSig = function () {
33 | var timestamp = new Date().getTime().toString();
34 | var sig = encrypt(appKey + timestamp + userId + secretKey);
35 | return { sig: sig, timestamp: timestamp, userId: userId };
36 | }
37 | let createUUID = (function (uuidRegEx, uuidReplacer) {
38 | return function () {
39 | return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(uuidRegEx, uuidReplacer).toUpperCase();
40 | };
41 | })(/[xy]/g, function (c) {
42 | let r = Math.random() * 16 | 0,
43 | v = c == "x" ? r : (r & 3 | 8);
44 | return v.toString(16);
45 | });
46 | let connectSig = getConnectSig();
47 | let startSig = getStartSig();
48 | requestParams['tokenId'] = requestParams['tokenId'] || createUUID()
49 | let params = {
50 | connect: {
51 | cmd: "connect",
52 | param: {
53 | sdk: {
54 | version: 16777472,
55 | source: 9,
56 | protocol: 2
57 | },
58 | app: {
59 | applicationId: appKey,
60 | sig: connectSig.sig,
61 | timestamp: connectSig.timestamp
62 | }
63 | }
64 | },
65 | start: {
66 | cmd: "start",
67 | param: {
68 | app: {
69 | applicationId: appKey,
70 | sig: startSig.sig,
71 | userId: startSig.userId,
72 | timestamp: startSig.timestamp
73 | },
74 | audio: {
75 | audioType: audioType,
76 | sampleRate: sampleRate,
77 | channel: 1,
78 | sampleBytes: 2
79 | },
80 | request: requestParams
81 | }
82 | }
83 | };
84 | return new Promise((resolve, reject) => {
85 | fs.readFile(audioPath)
86 | .then(audioData=> {
87 | let fd = new FormData();
88 | fd.append("text", JSON.stringify(params));
89 | fd.append("audio", audioData);
90 | let options = {
91 | host: baseHOST,
92 | path: "/" + coreType,
93 | method: "POST",
94 | protocol: "https:",
95 | headers: {"Request-Index": "0"}
96 | };
97 |
98 | try{
99 | const req = fd.submit(options, (err, res) => {
100 | if(err){
101 | return reject(new Error(err.message));
102 | }
103 | if(res.statusCode < 200 || res.statusCode > 299) {
104 | return reject(new Error(`HTTP status code ${res.statusCode}`));
105 | }
106 | const body = [];
107 | res.on('data', (chunk) => body.push(chunk));
108 | res.on('end', ()=>{
109 | const resString = Buffer.concat(body).toString();
110 | resolve(resString);
111 | });
112 | })
113 | }catch(e){
114 | reject(e);
115 | };
116 | }).catch(e=> {
117 | reject(e);
118 | })
119 | });
120 | }
121 |
122 |
123 | const requestParams = {
124 | coreType: coreType,
125 | refText: refText
126 | };
127 |
128 | doEval(userId, audioType, audioSampleRate, requestParams, audioPath)
129 | .then(data=>{console.log(data)})
130 | .catch(e=>{console.log(e)});
--------------------------------------------------------------------------------
/http_samples/nodejs_http_sample/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nodejs_http_sample",
3 | "version": "0.1.0",
4 | "private": true,
5 | "type": "module",
6 | "dependencies": {
7 | "crypto": "^1.0.1",
8 | "form-data": "^4.0.0"
9 | },
10 | "scripts": {
11 | "start": "node main.js"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/http_samples/nodejs_http_sample/supermarket.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/http_samples/nodejs_http_sample/supermarket.wav
--------------------------------------------------------------------------------
/http_samples/php_http_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 |
3 | 1. Install PHP (requirement: CURL library)
4 | 2. Modify the appKey in sample.php
5 | 3. Modify the secretKey in sample.php
6 | 4. Change the coreType according to your needs.
7 | 5. Change the reference text according to your needs.
8 | 6. Change the audio path corresponding to the reference text.
9 | 7. Change the audio type corresponding to the audio file.
10 | 8. Run the following command:
11 | ```
12 | php sample.php
13 | ```
--------------------------------------------------------------------------------
/http_samples/php_http_sample/sample.php:
--------------------------------------------------------------------------------
1 |
23 | '
24 | {
25 | "connect": {
26 | "cmd": "connect",
27 | "param": {
28 | "sdk": {
29 | "protocol": 2,
30 | "version": 16777472,
31 | "source": 9
32 | },
33 | "app": {
34 | "applicationId": "'.$appKey.'",
35 | "sig": "'. $conSig .'",
36 | "timestamp": "'. $ts.'"
37 | }
38 | }
39 | },
40 | "start": {
41 | "cmd": "start",
42 | "param": {
43 | "app": {
44 | "applicationId": "'.$appKey.'",
45 | "timestamp": "'.$ts.'",
46 | "sig": "'.$startSig.'",
47 | "userId": "'.$userId.'"
48 | },
49 | "audio": {
50 | "channel": 1,
51 | "sampleBytes": 2,
52 | "sampleRate": '.$audioSampleRate.',
53 | "audioType": "'.$audioType.'"
54 | },
55 | "request": {
56 | "tokenId": "uuu",
57 | "coreType": "'.$coreType.'",
58 | "refText": "'.$refText.'"
59 | }
60 | }
61 | }
62 | }
63 | ',
64 | 'audio'=>file_get_contents(ltrim($audioPath)));
65 | curl_setopt($ch, CURLOPT_URL, $url);
66 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
67 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
68 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
69 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
70 | curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
71 | curl_setopt($ch, CURLOPT_TIMEOUT_MS,30000);
72 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 30000);
73 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
74 | curl_setopt($ch, CURLOPT_POSTFIELDS, $strData);
75 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
76 | $output = curl_exec($ch);
77 | if($output === false)
78 | {
79 | echo 'Curl error: ' . curl_error($ch) . "\n";
80 | }
81 | curl_close($ch);
82 | echo ($output);
83 |
--------------------------------------------------------------------------------
/http_samples/php_http_sample/supermarket.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/http_samples/php_http_sample/supermarket.wav
--------------------------------------------------------------------------------
/http_samples/python_http_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 |
3 | 1. Install python
4 | 2. Modify the appKey in sample.py
5 | 3. Modify the secretKey in sample.py
6 | 4. Change the coreType according to your needs.
7 | 5. Change the reference text according to your needs.
8 | 6. Change the audio path corresponding to the reference text.
9 | 7. Change the audio type corresponding to the audio file.
10 | 8. Run the following command:
11 | ```
12 | python sample.py
13 | ```
--------------------------------------------------------------------------------
/http_samples/python_http_sample/sample.py:
--------------------------------------------------------------------------------
1 | #_*_encoding:utf-8_*_
2 | import time
3 | import hashlib
4 | import requests
5 | import json
6 |
7 | appKey = "Insert your appKey here"
8 | secretKey = "Insert your secretKey here"
9 |
10 | baseURL = "https://api.speechsuper.com/"
11 |
12 | timestamp = str(int(time.time()))
13 |
14 | coreType = "word.eval.promax" # Change the coreType according to your needs.
15 | refText = "supermarket" # Change the reference text according to your needs.
16 | audioPath = "supermarket.wav" # Change the audio path corresponding to the reference text.
17 | audioType = "wav" # Change the audio type corresponding to the audio file.
18 | audioSampleRate = 16000
19 | userId = "guest"
20 |
21 | url = baseURL + coreType
22 | connectStr = (appKey + timestamp + secretKey).encode("utf-8")
23 | connectSig = hashlib.sha1(connectStr).hexdigest()
24 | startStr = (appKey + timestamp + userId + secretKey).encode("utf-8")
25 | startSig = hashlib.sha1(startStr).hexdigest()
26 |
27 | params={
28 | "connect":{
29 | "cmd":"connect",
30 | "param":{
31 | "sdk":{
32 | "version":16777472,
33 | "source":9,
34 | "protocol":2
35 | },
36 | "app":{
37 | "applicationId":appKey,
38 | "sig":connectSig,
39 | "timestamp":timestamp
40 | }
41 | }
42 | },
43 | "start":{
44 | "cmd":"start",
45 | "param":{
46 | "app":{
47 | "userId":userId,
48 | "applicationId":appKey,
49 | "timestamp":timestamp,
50 | "sig":startSig
51 | },
52 | "audio":{
53 | "audioType":audioType,
54 | "channel":1,
55 | "sampleBytes":2,
56 | "sampleRate":audioSampleRate
57 | },
58 | "request":{
59 | "coreType":coreType,
60 | "refText":refText,
61 | "tokenId":"tokenId"
62 | }
63 |
64 | }
65 | }
66 | }
67 |
68 | datas=json.dumps(params)
69 | data={'text':datas}
70 | headers={"Request-Index":"0"}
71 | files={"audio":open(audioPath,'rb')}
72 | res=requests.post(url, data=data, headers=headers, files=files)
73 | print(res.text.encode('utf-8', 'ignore').decode('utf-8'))
74 |
--------------------------------------------------------------------------------
/http_samples/python_http_sample/supermarket.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/http_samples/python_http_sample/supermarket.wav
--------------------------------------------------------------------------------
/images/Flowchart.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/images/Flowchart.jpg
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 |
3 | 1. Install Miscrosoft Visual Studio 2017+ (requirement: Net Framework 4.6+)
4 | 2. Modify the appKey in csharp_websocket_sample/Program.cs
5 | 3. Modify the secretKey in csharp_websocket_sample/Program.cs
6 | 4. Change the coreType according to your needs.
7 | 5. Change the reference text according to your needs.
8 | 6. Change the audio path corresponding to the reference text.
9 | 7. Change the audio type corresponding to the audio file.
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/csharp_websocket_sample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28307.1705
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp_websocket_sample", "csharp_websocket_sample\csharp_websocket_sample.csproj", "{3B996F18-3740-4131-B3D5-2D3AA1A44E2B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {3B996F18-3740-4131-B3D5-2D3AA1A44E2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {3B996F18-3740-4131-B3D5-2D3AA1A44E2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {3B996F18-3740-4131-B3D5-2D3AA1A44E2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {3B996F18-3740-4131-B3D5-2D3AA1A44E2B}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {4678B448-ABDE-46CE-83B1-E532793C5CF9}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/csharp_websocket_sample/Program.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Linq;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Security.Cryptography;
7 | using System.Text;
8 | using System.Net.WebSockets;
9 | using System.Threading.Tasks;
10 |
11 | namespace csharp_websocket_sample
12 | {
13 | class Program
14 | {
15 | private static readonly string baseUrl = "wss://api.speechsuper.com/";
16 | private static readonly string appKey = "Insert your appKey here";
17 | private static readonly string secretKey = "Insert your secretKey here";
18 |
19 |
20 | public static async Task WebsocketAPIAsync(String audioPath, string audioType, int sampleRate, string coreType, Dictionary requests) {
21 | Dictionary paramDic = buildParams(audioType, sampleRate, requests);
22 | string connectionRequest = paramDic["connect"];
23 | string startRequest = paramDic["start"];
24 | string stopRequest = paramDic["stop"];
25 |
26 | WebSocketclient ws = new WebSocketclient();
27 | ws.OnClose = () =>
28 | {
29 | Console.WriteLine("Close connection to websocket");
30 | };
31 |
32 | ws.OnError = (Exception e) =>
33 | {
34 | Console.WriteLine($"error===>{e.StackTrace}");
35 | };
36 |
37 | ws.OnMessage = (string msg) =>
38 | {
39 | Console.WriteLine($"result===>{msg}");
40 | };
41 |
42 | await ws.ConnectAsync(baseUrl + coreType);
43 |
44 | //Send auth
45 | await ws.SendAsync(Encoding.UTF8.GetBytes(connectionRequest), WebSocketMessageType.Text);
46 |
47 | //Send start request
48 | await ws.SendAsync(Encoding.UTF8.GetBytes(startRequest), WebSocketMessageType.Text);
49 |
50 | //Send audio
51 | byte[] audio = FileContent(audioPath);
52 | await ws.SendAsync(audio, WebSocketMessageType.Binary);
53 |
54 | //Send stop request
55 | await ws.SendAsync(Encoding.UTF8.GetBytes(stopRequest), WebSocketMessageType.Text);
56 | }
57 |
58 | private static byte[] FileContent(string fileName)
59 | {
60 | using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
61 | {
62 | try
63 | {
64 | byte[] buffur = new byte[fs.Length];
65 | fs.Read(buffur,0,(int)fs.Length);
66 | fs.Read(buffur,0,(int)fs.Length);
67 | return buffur;
68 | }
69 | catch (Exception ex)
70 | {
71 | throw ex;
72 | }
73 | }
74 | }
75 |
76 | private static Dictionary buildParams(string audioType, int sampleRate, Dictionary requests)
77 | {
78 | Dictionary paramDic = new Dictionary();
79 |
80 | string userId = Guid.NewGuid().ToString();
81 | string ts = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();//timestamp
82 | string connectSigStr = appKey + ts + secretKey;
83 | string startSigStr = appKey + ts + userId + secretKey;
84 | string connectSig = sha1Hex(connectSigStr);
85 | string startSig = sha1Hex(startSigStr);
86 |
87 | //connect
88 | JObject connect = new JObject();
89 | connect.Add("cmd", "connect");
90 | JObject connectParam = new JObject();
91 |
92 | JObject connectParamSdk = new JObject();
93 | connectParamSdk.Add("protocol", 2);
94 | connectParamSdk.Add("version", 16777472);
95 | connectParamSdk.Add("source", 9);
96 | connectParam.Add("sdk", connectParamSdk);
97 |
98 | JObject connectParamApp = new JObject();
99 | connectParamApp.Add("applicationId", appKey);
100 | connectParamApp.Add("sig", connectSig);
101 | connectParamApp.Add("timestamp", ts);
102 | connectParam.Add("app", connectParamApp);
103 | connect.Add("param", connectParam);
104 |
105 | paramDic.Add("connect", connect.ToString());
106 |
107 | //start
108 | JObject start = new JObject();
109 | start.Add("cmd", "start");
110 | JObject startParam = new JObject();
111 |
112 | JObject startParamApp = new JObject();
113 | startParamApp.Add("applicationId", appKey);
114 | startParamApp.Add("sig", startSig);
115 | startParamApp.Add("timestamp", ts);
116 | startParamApp.Add("userId", userId);
117 | startParam.Add("app", startParamApp);
118 |
119 | JObject startParamAudio = new JObject();
120 | startParamAudio.Add("sampleBytes", 2);
121 | startParamAudio.Add("channel", 1);
122 | startParamAudio.Add("sampleRate", sampleRate);
123 | startParamAudio.Add("audioType", audioType);
124 | startParam.Add("audio", startParamAudio);
125 |
126 | JObject startParamRequest = new JObject();
127 | startParamRequest = (JObject)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(requests));
128 | startParamRequest.Add("tokenId", Guid.NewGuid().ToString());
129 | startParam.Add("request", startParamRequest);
130 |
131 | start.Add("param", startParam);
132 |
133 | paramDic.Add("start", start.ToString());
134 |
135 | //stop
136 | paramDic.Add("stop", "{\"cmd\":\"stop\"}");
137 |
138 | return paramDic;
139 | }
140 |
141 | private static string sha1Hex(string s)
142 | {
143 | try
144 | {
145 | SHA1 sha1 = new SHA1CryptoServiceProvider();
146 | byte[] bytesIn = Encoding.UTF8.GetBytes(s);
147 | byte[] bytesOut = sha1.ComputeHash(bytesIn);
148 | var sb = new StringBuilder();
149 | foreach (byte b in bytesOut)
150 | {
151 | sb.Append(b.ToString("x2"));
152 | }
153 |
154 | return sb.ToString().ToLower();
155 | }
156 | catch (Exception ex)
157 | {
158 | throw new Exception("SHA1 encryption error:" + ex.Message);
159 | }
160 | }
161 |
162 | static void Main(string[] args)
163 | {
164 | string coreType = "word.eval.promax"; // Change the coreType according to your needs.
165 | string refText = "supermarket" // Change the reference text according to your needs.
166 | string audioPath = "supermarket.wav"; // Change the audio path corresponding to the reference text.
167 | string audioType = "wav"; // Change the audio type corresponding to the audio file.
168 | int sampleRate = 16000;
169 |
170 | Dictionary requests = new Dictionary();
171 | requests.Add("coreType", coreType);
172 | requests.Add("refText", refText);
173 | WebsocketAPIAsync(audioPath, audioType, sampleRate, coreType, requests);
174 | Console.ReadLine();
175 | }
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/csharp_websocket_sample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("csharp_websocket_sample")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("csharp_websocket_sample")]
13 | [assembly: AssemblyCopyright("Copyright © 2022")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("3b996f18-3740-4131-b3d5-2d3aa1a44e2b")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/csharp_websocket_sample/WebSocketclient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Net.WebSockets;
6 | using System.Text;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 |
10 | namespace csharp_websocket_sample
11 | {
12 | class WebSocketclient
13 | {
14 | private readonly SemaphoreSlim sendResource = new SemaphoreSlim(1, 1);
15 |
16 | private readonly ClientWebSocket ws;
17 |
18 | private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
19 |
20 | public WebSocketclient()
21 | {
22 | ws = new ClientWebSocket();
23 | }
24 |
25 | public Action OnMessage { get; set; }
26 | public Action OnClose { get; set; }
27 | public Action OnError { get; set; }
28 |
29 | public async Task ConnectAsync(string url, CancellationToken cancellationToken = default(CancellationToken))
30 | {
31 | await ws.ConnectAsync(new Uri(url), cancellationToken).ConfigureAwait(false);
32 | Receive();
33 |
34 | }
35 |
36 | private async void Receive()
37 | {
38 | while(true)
39 | {
40 | byte[] bytes = new byte[4096];
41 |
42 | try
43 | {
44 | var result = await ws.ReceiveAsync(new ArraySegment(bytes), cancellationTokenSource.Token).ConfigureAwait(false);
45 | if(result != null && (result.CloseStatus.HasValue || result.MessageType == WebSocketMessageType.Close))
46 | {
47 | if (OnClose != null)
48 | {
49 | OnClose();
50 | }
51 | break;
52 | } else
53 | {
54 | using (var stream = new MemoryStream())
55 | {
56 | stream.Write(bytes, 0, result.Count);
57 | while (!result.EndOfMessage)
58 | {
59 | result = await ws.ReceiveAsync(new ArraySegment(bytes), CancellationToken.None);
60 | stream.Write(bytes, 0, result.Count);
61 | }
62 |
63 | stream.Seek(0, SeekOrigin.Begin);
64 | using (var reader = new StreamReader(stream, Encoding.UTF8))
65 | {
66 | string message = reader.ReadToEnd();
67 | if(OnMessage != null)
68 | {
69 | OnMessage(message);
70 | }
71 | }
72 | }
73 | }
74 | } catch(OperationCanceledException)
75 | {
76 | if(OnClose != null)
77 | {
78 | OnClose();
79 | }
80 | break;
81 | } catch (Exception e)
82 | {
83 | if(OnError != null)
84 | {
85 | OnError(e);
86 | }
87 | break;
88 | }
89 | }
90 | }
91 |
92 | public async Task SendAsync(byte[] buffer, WebSocketMessageType messageType, CancellationToken _cancellationToken = default(CancellationToken))
93 | {
94 | await sendResource.WaitAsync(_cancellationToken).ConfigureAwait(false);
95 | try
96 | {
97 | var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationToken, cancellationTokenSource.Token);
98 | await ws.SendAsync(new ArraySegment(buffer), messageType, true, linkedTokenSource.Token).ConfigureAwait(false);
99 | }finally
100 | {
101 | sendResource.Release();
102 | }
103 | }
104 |
105 | public void Cancel()
106 | {
107 | cancellationTokenSource.Cancel();
108 | if (ws != null)
109 | {
110 | if(ws.State == WebSocketState.Open)
111 | {
112 | ws.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None);
113 | ws.Dispose();
114 | }
115 | }
116 | }
117 |
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/csharp_websocket_sample/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/csharp_websocket_sample/bin/Debug/supermarket.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/websocket_samples/csharp_websocket_sample/csharp_websocket_sample/bin/Debug/supermarket.wav
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/csharp_websocket_sample/csharp_websocket_sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {3B996F18-3740-4131-B3D5-2D3AA1A44E2B}
8 | Exe
9 | csharp_websocket_sample
10 | csharp_websocket_sample
11 | v4.6
12 | 512
13 | true
14 |
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 | false
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 | false
36 |
37 |
38 |
39 | ..\packages\Newtonsoft.Json.13.0.1\lib\net40\Newtonsoft.Json.dll
40 |
41 |
42 |
43 |
44 | ..\packages\System.Net.WebSockets.4.3.0\lib\net46\System.Net.WebSockets.dll
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/websocket_samples/csharp_websocket_sample/csharp_websocket_sample/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/websocket_samples/golang_websocket_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 |
3 | 1. Install Golang
4 | 2. Modify the appKey in sample.go
5 | 3. Modify the secretKey in sample.go
6 | 4. Change the coreType according to your needs.
7 | 5. Change the reference text according to your needs.
8 | 6. Change the audio path corresponding to the reference text.
9 | 7. Change the audio type corresponding to the audio file.
10 | 8. Run the app
--------------------------------------------------------------------------------
/websocket_samples/golang_websocket_sample/go.mod:
--------------------------------------------------------------------------------
1 | module golang_websocket_sample
2 |
3 | go 1.15
4 |
5 | require (
6 | github.com/google/uuid v1.3.0
7 | github.com/gorilla/websocket v1.5.0
8 | )
9 |
--------------------------------------------------------------------------------
/websocket_samples/golang_websocket_sample/sample.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | //Import packages used by the project
4 | import (
5 | "crypto/sha1"
6 | "sync"
7 |
8 | "flag"
9 | "fmt"
10 | "io/ioutil"
11 | "strconv"
12 |
13 | "log"
14 |
15 | "os"
16 | "os/signal"
17 | "time"
18 |
19 | "github.com/google/uuid"
20 | "github.com/gorilla/websocket"
21 | )
22 |
23 |
24 | func main() {
25 | flag.Parse()
26 | log.SetFlags(0)
27 |
28 | interrupt := make(chan os.Signal, 1)
29 | signal.Notify(interrupt, os.Interrupt)
30 |
31 | appKey := "Insert your appKey here"
32 | secretKey := "Insert your secretKey here"
33 |
34 | baseURL := "wss://api.speechsuper.com/"
35 |
36 | coreType := "word.eval.promax" // Change the coreType according to your needs.
37 | refText := "supermarket" // Change the reference text according to your needs.
38 | audioPath := "supermarket.wav" // Change the audio path corresponding to the reference text.
39 | audioType := "wav" // Change the audio type corresponding to the audio file.
40 | audioSampleRate := "16000"
41 | userId := "guest" // Required and customizable. This value is required when generating startSig
42 |
43 | //create connect
44 | url := baseURL + coreType
45 | wsClient, _, err := websocket.DefaultDialer.Dial(url, nil)
46 | if err != nil {
47 | log.Fatal("dial:", err)
48 | }
49 |
50 | wg := new(sync.WaitGroup)
51 | wg.Add(1)
52 |
53 | go func(wsClient *websocket.Conn) {
54 | defer wg.Done()
55 | _, message, err := wsClient.ReadMessage()
56 | if err != nil {
57 | log.Println("websocket error:", err)
58 | return
59 | }
60 | log.Printf("result===> %s", message)
61 | }(wsClient)
62 |
63 | //send connect request
64 | timestamp := strconv.FormatInt(time.Now().Unix(), 10)
65 | data := []byte(appKey + timestamp + secretKey)
66 | connectSig := fmt.Sprintf("%x", sha1.Sum(data))
67 | //connect param
68 | connectStr := `{"cmd":"connect","param":{"sdk":{"version":16777472,"source":1,"protocol":1},"app":{"applicationId":"`+ appKey + `","sig":"` + connectSig + `","timestamp":"` + timestamp + `"}}}`
69 | wsClient.WriteMessage(websocket.TextMessage, []byte(connectStr))
70 |
71 | //send start request
72 | timestamp = strconv.FormatInt(time.Now().Unix(), 10)
73 | data = []byte(appKey + timestamp + userId + secretKey)
74 | startSig := fmt.Sprintf("%x", sha1.Sum(data))
75 | tokenId := uuid.New().String()
76 | //start param
77 | startStr := `{"cmd":"start","param":{"app":{"applicationId":"` + appKey + `","sig":"` + startSig+ `","timestamp":"` + timestamp + `","userId":"` + userId + `"},"audio":{"audioType":"` + audioType + `","sampleRate":` + audioSampleRate + `,"channel":1,"sampleBytes":2},"request":{"coreType":"` + coreType + `","refText":"` + refText + `","tokenId":"` + tokenId + `"}}}`
78 | wsClient.WriteMessage(websocket.TextMessage, []byte(startStr))
79 |
80 | //send audio
81 | f, _ := os.Open(audioPath)
82 | defer f.Close()
83 | voiceBytes, _ := ioutil.ReadAll(f)
84 | wsClient.WriteMessage(websocket.BinaryMessage, voiceBytes)
85 |
86 | //send stop request
87 | stopStr := `{"cmd":"stop"}`
88 | wsClient.WriteMessage(websocket.TextMessage, []byte(stopStr))
89 |
90 | wg.Wait()
91 | }
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/websocket_samples/golang_websocket_sample/supermarket.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/speechsuper/SpeechSuper-API-Samples/0d6bb10ca7a86e62a9848c81225f1a17d189ce27/websocket_samples/golang_websocket_sample/supermarket.wav
--------------------------------------------------------------------------------
/websocket_samples/java_websocket_sample/README.md:
--------------------------------------------------------------------------------
1 | # Quick Start
2 | - Modify the appKey in src\main\java\com\speechsuper\Sample.java
3 | - Modify the secretKey in src\main\java\com\speechsuper\Sample.java
4 | - Change the coreType according to your needs.
5 | - Change the reference text according to your needs.
6 | - Change the audio path corresponding to the reference text.
7 | - Change the audio type corresponding to the audio file.
8 |
9 | # Requirements
10 | - Java JDK 1.7+
11 | - Maven
12 |
13 | # Command lines
14 | - Compile:
15 | ```
16 | mvn clean compile
17 | ```
18 | - Run the `Sample` class:
19 | ```
20 | mvn compile exec:java -Dexec.mainClass="com.speechsuper.Sample"
21 | ```
--------------------------------------------------------------------------------
/websocket_samples/java_websocket_sample/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.speechsuper
6 | java_websocket_sample
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | java_websocket_sample
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 3.8.1
22 | test
23 |
24 |
25 | commons-codec
26 | commons-codec
27 | 1.15
28 |
29 |
30 | org.java-websocket
31 | Java-WebSocket
32 | 1.5.2
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/websocket_samples/java_websocket_sample/src/main/java/com/speechsuper/Sample.java:
--------------------------------------------------------------------------------
1 | package com.speechsuper;
2 |
3 | import org.apache.commons.codec.binary.Hex;
4 | import org.apache.commons.codec.digest.DigestUtils;
5 | import org.java_websocket.client.WebSocketClient;
6 | import org.java_websocket.handshake.ServerHandshake;
7 |
8 | import java.io.IOException;
9 | import java.net.URISyntaxException;
10 | import java.security.MessageDigest;
11 | import java.net.URI;
12 | import java.util.ArrayList;
13 | import java.io.FileInputStream;
14 | import java.io.FileNotFoundException;
15 |
16 | public class Sample {
17 | public static final String baseUrl = "wss://api.speechsuper.com/";
18 | public static final String appKey = "Insert your appKey here";
19 | public static final String secretKey = "Insert your secretKey here";
20 |
21 | public static void WebsocketAPI(String audioPath, String audioType, String audioSampleRate, String refText, String coreType) {
22 | String url = baseUrl + coreType;
23 | //Randomly generate userId
24 | String userId = getRandomString(5);
25 | final ArrayList