Skip to content

Commit b941175

Browse files
esgrahamesgraham13
andauthored
Implement startListening (#37)
* Added plugin and native ionic code * Removed the cognitive services plugin .DS_Store file from gitignore, and added all .DS_Store files. * Renamed Native Ionic Folder. Updated Readme. * Added images for README * Renamed cognitiveservicesPlugin folder * Updated Android source to download aar file using gradle, rather than including aar file in code. * Remove vscode files. * Added startListening to Android and renamed recongizefromMicrophone on iOS. * Updated code to work on iOS * Updated example app to use startListening * Updates to example iOS app * Updated Plugin ReadMe * Added startListening to the example app. The stopListening is crashing on Android as it is not implmented yet. * Update If statement in startListening example code. * Removed unnessary imports in java and console.log statements Co-authored-by: esgraham13 <[email protected]>
1 parent dbe22aa commit b941175

27 files changed

+443
-3675
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
cognitiveservicesPlugin/node_modules/
33
cognitiveservicesPlugin/.gradle/
44
cognitiveservicesPlugin/platforms/
5-
cognitiveservicesPlugin/src/ios/MicrosoftCognitiveServicesSpeech.framework/
6-
cognitiveservicesPlugin/aar
75
.vscode/
6+
cognitiveservicesPlugin/local.properties
7+
examples/ionic-angular/platforms
8+
examples/ionic-angular/src/environments/

cognitiveservices/index.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ export declare class CognitiveServicesOriginal extends IonicNativePlugin {
3333
* @param arg2 {number} Another param to configure something
3434
* @return {Promise<any>} Returns a promise that resolves when something happens
3535
*/
36-
SetSubscription(speechSubscriptionKey: string, serviceRegion: string): Promise<void>;
37-
RecognizeFromMicrophone(): Observable<Array<Object>>;
38-
SpeakSsml(speechText: string): Promise<string>;
39-
SpeakSsmlAsync(speechText: string): Promise<string>;
40-
StartSpeaking(speechText: string): Promise<string>;
41-
SpeakTextAsync(speechText: string): Promise<string>;
42-
StopListening(): Promise<void>;
36+
init(speechKey: string, serviceRegion: string): Promise<void>;
37+
startListening(): Observable<Array<Object>>;
38+
startSpeakingSsml(speechText: string): Promise<string>;
39+
startSpeaking(speechText: string): Promise<string>;
40+
stopListening(): Promise<void>;
4341
SpeakWithVoiceOptions(speechText: string, options?: SpeechVoiceOptions): Promise<void>;
44-
SpeakStop(): Promise<void>;
42+
stopSpeaking(): Promise<void>;
4543
}
4644

4745
export declare const CognitiveServices: CognitiveServicesOriginal;

cognitiveservices/index.js

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cognitiveservices/ngx/index.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ export declare class CognitiveServices extends IonicNativePlugin {
3333
* @param arg2 {number} Another param to configure something
3434
* @return {Promise<any>} Returns a promise that resolves when something happens
3535
*/
36-
SetSubscription(speechSubscriptionKey: string, serviceRegion: string): Promise<void>;
37-
RecognizeFromMicrophone(): Observable<Array<Object>>;
38-
SpeakSsml(speechText: string): Promise<string>;
39-
SpeakSsmlAsync(speechText: string): Promise<string>;
40-
StartSpeaking(speechText: string): Promise<string>;
41-
SpeakTextAsync(speechText: string): Promise<string>;
42-
StopListening(): Promise<void>;
36+
init(speechKey: string, serviceRegion: string): Promise<void>;
37+
startListening(): Observable<Array<Object>>;
38+
startSpeakingSsml(speechText: string): Promise<string>;
39+
startSpeaking(speechText: string): Promise<string>;
40+
stopListening(): Promise<void>;
4341
SpeakWithVoiceOptions(speechText: string, options?: SpeechVoiceOptions): Promise<void>;
44-
SpeakStop(): Promise<void>;
42+
stopSpeaking(): Promise<void>;
4543
}

cognitiveservices/ngx/index.js

Lines changed: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cognitiveservices/ngx/index.metadata.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
}
2727
],
2828
"members": {
29-
"SetSubscription": [{ "__symbolic": "method" }],
30-
"RecognizeFromMicrophone": [{ "__symbolic": "method" }],
31-
"SpeakSsml": [{ "__symbolic": "method" }],
32-
"SpeakSsmlAsync": [{ "__symbolic": "method" }],
33-
"SpeakText": [{ "__symbolic": "method" }],
34-
"SpeakTextAsync": [{ "__symbolic": "method" }],
35-
"StopListening": [{ "__symbolic": "method" }],
36-
"SpeakWithVoiceOptions": [{ "__symbolic": "method" }],
37-
"SpeakStop": [{ "__symbolic": "method" }]
29+
"init": [{ "__symbolic": "method" }],
30+
"startListening": [{ "__symbolic": "method" }],
31+
"startSpeakingSsml": [{ "__symbolic": "method" }],
32+
"startSpeaking": [{ "__symbolic": "method" }],
33+
"stopListening": [{ "__symbolic": "method" }],
34+
"speakWithVoiceOptions": [{ "__symbolic": "method" }],
35+
"stopSpeaking": [{ "__symbolic": "method" }]
3836
}
3937
}
4038
}

cognitiveservicesPlugin/README.md

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ To create a Speech Resource, follow the instructions in the Azure
4343
documentation: [Try the Speech service for
4444
free](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started#create-a-speech-resource-in-azure).
4545

46-
### SetSubscription (string speechSubscriptionKey, string serviceRegion)
46+
### init (string speechSubscriptionKey, string serviceRegion)
4747

4848
```js
49-
microsoft.plugin.cognitiveservices.SetSubscription(string speechSubscriptionKey,
49+
microsoft.plugin.cognitiveservices.init(string speechSubscriptionKey,
5050
string serviceRegion, Function successCallback, Function errorCallback)
5151
```
5252

@@ -58,29 +58,29 @@ subscription](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-s
5858
For more information read [About
5959
regions](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started#about-regions)
6060

61-
SetSubscription creates the Cognitive Services speech configuration and
61+
init creates the Cognitive Services speech configuration and
6262
requires the subscription and region of the Azure Speech resource.
6363

64-
SetSubscription must be called before the plugin can be used by other
64+
init must be called before the plugin can be used by other
6565
method. Recommended to call the SetSubscription method in the
6666
InitializingApp method.
6767

68-
###StartSpeaking (string speechText)
68+
### startSpeaking (string speechText)
6969

7070
**Speech Text**: The text that will be spoken by the audio player.
7171

7272
```js
73-
microsoft.plugin.cognitiveservices.StartSpeaking(string speechText, Function
73+
microsoft.plugin.cognitiveservices.startSpeaking(string speechText, Function
7474
successCallback, Function errorCallback)
7575
```
7676

7777
StartSpeaking uses the Speech SDK to playback the text that is sent to the
7878
function.
7979

80-
### SpeakSsml (string speechText)
80+
### startSpeakingSSML (string speechText)
8181

8282
```js
83-
microsoft.plugin.cognitiveservices.SpeakSsml(string speechText, Function
83+
microsoft.plugin.cognitiveservices.startSpeakingSSML(string speechText, Function
8484
successCallback, Function errorCallback)
8585
```
8686

@@ -95,10 +95,10 @@ synthesized speech using the text-to-speech service. Compared to plain
9595
text, SSML allows developers to fine-tune the pitch, pronunciation,
9696
speaking rate, volume, and more of the text-to-speech output.
9797

98-
### RecognizeFromMicrophone ()
98+
### startListening()
9999

100100
```js
101-
microsoft.plugin.cognitiveservices.RecognizeFromMicrophone (Function
101+
microsoft.plugin.cognitiveservices.startListening (Function
102102
successCallback, Function errorCallback)
103103
```
104104

@@ -114,9 +114,7 @@ processing the spoken words.
114114

115115
The return value is a set of string values.
116116

117-
iOS Only.
118-
119-
### StopListening()
117+
### stopListening()
120118

121119
```js
122120
microsoft.plugin.cognitiveservices.stopListening(Function successCallback,
@@ -127,10 +125,10 @@ Stop the recognition process. No return value.
127125

128126
iOS Only.
129127

130-
### SpeakStop()
128+
### stopSpeaking()
131129

132130
```js
133-
microsoft.plugin.cognitiveservices.speakStop(Function successCallback, Function errorCallback)
131+
microsoft.plugin.cognitiveservices.stopSpeaking(Function successCallback, Function errorCallback)
134132
```
135133

136134
Stops the AVPlayer from playing. No return value.
@@ -229,7 +227,7 @@ constructor(private cognitiveServices: CognitiveServices) { }
229227
// Set the subscription information
230228
initializeApp() {
231229
this.platform.ready().then(() => {
232-
this.cognitiveServices.SetSubscription(
230+
this.cognitiveServices.init(
233231
environment.subscriptionKey,
234232
environment.serviceRegion).then(
235233
() => { },
@@ -248,7 +246,7 @@ constructor(private cognitiveServices: CognitiveServices) { }
248246
...
249247

250248
// Start the recognition process (iOS only)
251-
this.cognitiveServices.RecognizeFromMicrophone().subscribe(
249+
this.cognitiveServices.startListening().subscribe(
252250
results => {
253251
if (!results.isFinal) {
254252
matches = results.result;
@@ -264,22 +262,22 @@ constructor(private cognitiveServices: CognitiveServices) { }
264262

265263

266264
// Stop the recognition process (iOS only)
267-
this.cognitiveServices.StopListening();
265+
this.cognitiveServices.stopListening();
268266

269267
// Speak the text in the StartSpeaking variable
270-
this.cognitiveServices.StartSpeaking(textToSpeak).then(
268+
this.cognitiveServices.startSpeaking(textToSpeak).then(
271269
() => {},
272270
(error: any) => {alert(error);}
273271
);
274272

275273
// Speak using the SSML xml values
276-
this.cognitiveServices.SpeakSsml(speakSsml).then(
274+
this.cognitiveServices.startSpeakingSsml(speakSsml).then(
277275
() => {},
278276
(error: any) => {alert(error); }
279277
);
280278

281279
// Stop the speaking process (iOS only)
282-
this.cognitiveServices.SpeakStop();
280+
this.cognitiveServices.stopSpeaking();
283281
```
284282
285283
## Ionic Native
@@ -319,7 +317,7 @@ permission
319317
320318
The Java SDK for Android is packaged as an AAR (Android Library), which
321319
includes the necessary libraries and required Android permissions. The
322-
Speech AAR is included with the plugin code.
320+
Speech AAR is downloaded during the installation process using gradle.
323321
324322
### Files
325323
@@ -334,8 +332,6 @@ client-sdk-1.8.0 AAR dependency
334332
The following file is found under the cognitiveServicesPlugin/aar
335333
directory:
336334
337-
- **client-sdk-1.8.0.aar** -- The Cognitive Services Android Library
338-
339335
### Further readings
340336
341337
- <https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-sdk#android>

cognitiveservicesPlugin/config.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,4 @@
2727
</platform>
2828
<plugin name="cordova-plugin-whitelist" spec="1" />
2929
<engine name="browser" spec="^5.0.4" />
30-
<engine name="ios" spec="^5.1.1" />
3130
</widget>

0 commit comments

Comments
 (0)