Skip to content

Commit

Permalink
Implement startListening (#37)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
esgraham and esgraham13 authored Mar 5, 2020
1 parent dbe22aa commit b941175
Show file tree
Hide file tree
Showing 27 changed files with 443 additions and 3,675 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
cognitiveservicesPlugin/node_modules/
cognitiveservicesPlugin/.gradle/
cognitiveservicesPlugin/platforms/
cognitiveservicesPlugin/src/ios/MicrosoftCognitiveServicesSpeech.framework/
cognitiveservicesPlugin/aar
.vscode/
cognitiveservicesPlugin/local.properties
examples/ionic-angular/platforms
examples/ionic-angular/src/environments/
14 changes: 6 additions & 8 deletions cognitiveservices/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ export declare class CognitiveServicesOriginal extends IonicNativePlugin {
* @param arg2 {number} Another param to configure something
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
SetSubscription(speechSubscriptionKey: string, serviceRegion: string): Promise<void>;
RecognizeFromMicrophone(): Observable<Array<Object>>;
SpeakSsml(speechText: string): Promise<string>;
SpeakSsmlAsync(speechText: string): Promise<string>;
StartSpeaking(speechText: string): Promise<string>;
SpeakTextAsync(speechText: string): Promise<string>;
StopListening(): Promise<void>;
init(speechKey: string, serviceRegion: string): Promise<void>;
startListening(): Observable<Array<Object>>;
startSpeakingSsml(speechText: string): Promise<string>;
startSpeaking(speechText: string): Promise<string>;
stopListening(): Promise<void>;
SpeakWithVoiceOptions(speechText: string, options?: SpeechVoiceOptions): Promise<void>;
SpeakStop(): Promise<void>;
stopSpeaking(): Promise<void>;
}

export declare const CognitiveServices: CognitiveServicesOriginal;
13 changes: 5 additions & 8 deletions cognitiveservices/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions cognitiveservices/ngx/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ export declare class CognitiveServices extends IonicNativePlugin {
* @param arg2 {number} Another param to configure something
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
SetSubscription(speechSubscriptionKey: string, serviceRegion: string): Promise<void>;
RecognizeFromMicrophone(): Observable<Array<Object>>;
SpeakSsml(speechText: string): Promise<string>;
SpeakSsmlAsync(speechText: string): Promise<string>;
StartSpeaking(speechText: string): Promise<string>;
SpeakTextAsync(speechText: string): Promise<string>;
StopListening(): Promise<void>;
init(speechKey: string, serviceRegion: string): Promise<void>;
startListening(): Observable<Array<Object>>;
startSpeakingSsml(speechText: string): Promise<string>;
startSpeaking(speechText: string): Promise<string>;
stopListening(): Promise<void>;
SpeakWithVoiceOptions(speechText: string, options?: SpeechVoiceOptions): Promise<void>;
SpeakStop(): Promise<void>;
stopSpeaking(): Promise<void>;
}
15 changes: 6 additions & 9 deletions cognitiveservices/ngx/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions cognitiveservices/ngx/index.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
}
],
"members": {
"SetSubscription": [{ "__symbolic": "method" }],
"RecognizeFromMicrophone": [{ "__symbolic": "method" }],
"SpeakSsml": [{ "__symbolic": "method" }],
"SpeakSsmlAsync": [{ "__symbolic": "method" }],
"SpeakText": [{ "__symbolic": "method" }],
"SpeakTextAsync": [{ "__symbolic": "method" }],
"StopListening": [{ "__symbolic": "method" }],
"SpeakWithVoiceOptions": [{ "__symbolic": "method" }],
"SpeakStop": [{ "__symbolic": "method" }]
"init": [{ "__symbolic": "method" }],
"startListening": [{ "__symbolic": "method" }],
"startSpeakingSsml": [{ "__symbolic": "method" }],
"startSpeaking": [{ "__symbolic": "method" }],
"stopListening": [{ "__symbolic": "method" }],
"speakWithVoiceOptions": [{ "__symbolic": "method" }],
"stopSpeaking": [{ "__symbolic": "method" }]
}
}
}
Expand Down
44 changes: 20 additions & 24 deletions cognitiveservicesPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ To create a Speech Resource, follow the instructions in the Azure
documentation: [Try the Speech service for
free](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started#create-a-speech-resource-in-azure).

### SetSubscription (string speechSubscriptionKey, string serviceRegion)
### init (string speechSubscriptionKey, string serviceRegion)

```js
microsoft.plugin.cognitiveservices.SetSubscription(string speechSubscriptionKey,
microsoft.plugin.cognitiveservices.init(string speechSubscriptionKey,
string serviceRegion, Function successCallback, Function errorCallback)
```

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

SetSubscription creates the Cognitive Services speech configuration and
init creates the Cognitive Services speech configuration and
requires the subscription and region of the Azure Speech resource.

SetSubscription must be called before the plugin can be used by other
init must be called before the plugin can be used by other
method. Recommended to call the SetSubscription method in the
InitializingApp method.

###StartSpeaking (string speechText)
### startSpeaking (string speechText)

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

```js
microsoft.plugin.cognitiveservices.StartSpeaking(string speechText, Function
microsoft.plugin.cognitiveservices.startSpeaking(string speechText, Function
successCallback, Function errorCallback)
```

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

### SpeakSsml (string speechText)
### startSpeakingSSML (string speechText)

```js
microsoft.plugin.cognitiveservices.SpeakSsml(string speechText, Function
microsoft.plugin.cognitiveservices.startSpeakingSSML(string speechText, Function
successCallback, Function errorCallback)
```

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

### RecognizeFromMicrophone ()
### startListening()

```js
microsoft.plugin.cognitiveservices.RecognizeFromMicrophone (Function
microsoft.plugin.cognitiveservices.startListening (Function
successCallback, Function errorCallback)
```

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

The return value is a set of string values.

iOS Only.

### StopListening()
### stopListening()

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

iOS Only.

### SpeakStop()
### stopSpeaking()

```js
microsoft.plugin.cognitiveservices.speakStop(Function successCallback, Function errorCallback)
microsoft.plugin.cognitiveservices.stopSpeaking(Function successCallback, Function errorCallback)
```

Stops the AVPlayer from playing. No return value.
Expand Down Expand Up @@ -229,7 +227,7 @@ constructor(private cognitiveServices: CognitiveServices) { }
// Set the subscription information
initializeApp() {
this.platform.ready().then(() => {
this.cognitiveServices.SetSubscription(
this.cognitiveServices.init(
environment.subscriptionKey,
environment.serviceRegion).then(
() => { },
Expand All @@ -248,7 +246,7 @@ constructor(private cognitiveServices: CognitiveServices) { }
...

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


// Stop the recognition process (iOS only)
this.cognitiveServices.StopListening();
this.cognitiveServices.stopListening();

// Speak the text in the StartSpeaking variable
this.cognitiveServices.StartSpeaking(textToSpeak).then(
this.cognitiveServices.startSpeaking(textToSpeak).then(
() => {},
(error: any) => {alert(error);}
);

// Speak using the SSML xml values
this.cognitiveServices.SpeakSsml(speakSsml).then(
this.cognitiveServices.startSpeakingSsml(speakSsml).then(
() => {},
(error: any) => {alert(error); }
);

// Stop the speaking process (iOS only)
this.cognitiveServices.SpeakStop();
this.cognitiveServices.stopSpeaking();
```
## Ionic Native
Expand Down Expand Up @@ -319,7 +317,7 @@ permission
The Java SDK for Android is packaged as an AAR (Android Library), which
includes the necessary libraries and required Android permissions. The
Speech AAR is included with the plugin code.
Speech AAR is downloaded during the installation process using gradle.
### Files
Expand All @@ -334,8 +332,6 @@ client-sdk-1.8.0 AAR dependency
The following file is found under the cognitiveServicesPlugin/aar
directory:
- **client-sdk-1.8.0.aar** -- The Cognitive Services Android Library
### Further readings
- <https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/speech-sdk#android>
Expand Down
1 change: 0 additions & 1 deletion cognitiveservicesPlugin/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@
</platform>
<plugin name="cordova-plugin-whitelist" spec="1" />
<engine name="browser" spec="^5.0.4" />
<engine name="ios" spec="^5.1.1" />
</widget>
Loading

0 comments on commit b941175

Please sign in to comment.