Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
OvidijusParsiunas committed Aug 15, 2023
1 parent f567448 commit 6a59ecd
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 55 deletions.
53 changes: 29 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install speech-to-element
import SpeechToElement from 'speech-to-element';
const targetElement = document.getElementById('target-element');
SpeechToElement.toggle("webspeech", {element: targetElement});
SpeechToElement.toggle('webspeech', {element: targetElement});
```

[CDN](https://cdn.jsdelivr.net/gh/ovidijusparsiunas/speech-to-element@master/component/bundle/index.min.js):
Expand All @@ -32,7 +32,7 @@ SpeechToElement.toggle("webspeech", {element: targetElement});

```
const targetElement = document.getElementById('target-element');
window.SpeechToElement.toggle("webspeech", {element: targetElement});
window.SpeechToElement.toggle('webspeech', {element: targetElement});
```

When using Azure, you will also need to install its speech [SDK](https://www.npmjs.com/package/microsoft-cognitiveservices-speech-sdk). Read more in the [Azure SDK](#floppy_disk-azure-sdk) section. <br />
Expand All @@ -57,9 +57,9 @@ Examples:

```
SpeechToElement.startWebSpeech({element: targetElement, displayInterimResults: false});
SpeechToElement.startAzure({element: targetElement, region: "westus", token: "token"});
SpeechToElement.toggle("webspeech", {element: targetElement, language: "en-US"});
SpeechToElement.toggle("azure", {element: targetElement, region: "eastus", subscriptionKey: "key"});
SpeechToElement.startAzure({element: targetElement, region: 'westus', token: 'token'});
SpeechToElement.toggle('webspeech', {element: targetElement, language: 'en-US'});
SpeechToElement.toggle('azure', {element: targetElement, region: 'eastus', subscriptionKey: 'key'});
SpeechToElement.stop();
SpeechToElement.endCommandMode();
```
Expand Down Expand Up @@ -89,8 +89,8 @@ Generic options for the speech to element functionality:
Examples:

```
SpeechToElement.toggle("webspeech", {element: targetElement, translations: {hi: 'bye', Hi: 'Bye'}});
SpeechToElement.toggle("webspeech", {onResult: (text) => console.log(text)});
SpeechToElement.toggle('webspeech', {element: targetElement, translations: {hi: 'bye', Hi: 'Bye'}});
SpeechToElement.toggle('webspeech', {onResult: (text) => console.log(text)});
```

##### TextColor:
Expand All @@ -105,7 +105,7 @@ Object used to set the color for transcription result text (does not work for `i
Example:

```
SpeechToElement.toggle("webspeech", {
SpeechToElement.toggle('webspeech', {
element: targetElement, textColor: {interim: 'grey', final: 'black'}
});
```
Expand All @@ -129,13 +129,13 @@ Object used to set the phrases of commands that will control transcription and i
Example:

```
SpeechToElement.toggle("webspeech", {
SpeechToElement.toggle('webspeech', {
element: targetElement,
commands: {
pause: "pause",
resume: "resume",
removeAllText: "remove text",
commandMode: "command"
pause: 'pause',
resume: 'resume',
removeAllText: 'remove text',
commandMode: 'command'
}
});
```
Expand All @@ -152,13 +152,13 @@ Object used to configure how the command phrases are interpreted:
Example:

```
SpeechToElement.toggle("webspeech", {
SpeechToElement.toggle('webspeech', {
element: targetElement,
commands: {
removeAllText: "remove text"
"settings": {
"substrings": true,
"caseSensitive": false
removeAllText: 'remove text',
settings: {
substrings: true,
caseSensitive: false
}}
});
```
Expand All @@ -176,10 +176,10 @@ Result object for the `onPreResult` function. This can be used to control the sp
Example for a creating a custom command:

```
SpeechToElement.toggle("webspeech", {
SpeechToElement.toggle('webspeech', {
element: targetElement,
onPreResult: (text) => {
if (text.toLowerCase().includes("custom command")) {
if (text.toLowerCase().includes('custom command')) {
SpeechToElement.endCommandMode();
your custom code here
return {restart: true, removeNewText: true};
Expand All @@ -198,12 +198,12 @@ Custom options for the [Web Speech API](https://developer.mozilla.org/en-US/docs
Example:

```
SpeechToElement.toggle("webspeech", {element: targetElement, language: "en-GB"});
SpeechToElement.toggle('webspeech', {element: targetElement, language: 'en-GB'});
```

##### AzureOptions:

Options for the [Azure Cognitive Speech Services API](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-to-text). This object requires `region` and either `retrieveToken`, `subscriptionKey` or the `token` properties to be defined with it:
Options for the [Azure Cognitive Speech Services API](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-to-text). This object REQUIRES `region` and either `retrieveToken` or `subscriptionKey` or `token` properties to be defined with it:

| Name | Type | Description |
| :----------------- | :---------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -217,9 +217,14 @@ Options for the [Azure Cognitive Speech Services API](https://learn.microsoft.co
Examples:

```
SpeechToElement.toggle("azure", {element: targetElement, token: "token", language: "ja-JP"});
SpeechToElement.toggle('azure', {
element: targetElement,
region: 'eastus',
token: 'token',
language: 'ja-JP'
});
SpeechToElement.toggle("azure", {
SpeechToElement.toggle('azure', {
element: targetElement,
region: 'southeastasia',
retrieveToken: async () => {
Expand Down
53 changes: 29 additions & 24 deletions component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm install speech-to-element
import SpeechToElement from 'speech-to-element';
const targetElement = document.getElementById('target-element');
SpeechToElement.toggle("webspeech", {element: targetElement});
SpeechToElement.toggle('webspeech', {element: targetElement});
```

[CDN](https://cdn.jsdelivr.net/gh/ovidijusparsiunas/speech-to-element@master/component/bundle/index.min.js):
Expand All @@ -32,7 +32,7 @@ SpeechToElement.toggle("webspeech", {element: targetElement});

```
const targetElement = document.getElementById('target-element');
window.SpeechToElement.toggle("webspeech", {element: targetElement});
window.SpeechToElement.toggle('webspeech', {element: targetElement});
```

When using Azure, you will also need to install its speech [SDK](https://www.npmjs.com/package/microsoft-cognitiveservices-speech-sdk). Read more in the [Azure SDK](#floppy_disk-azure-sdk) section. <br />
Expand Down Expand Up @@ -70,9 +70,9 @@ Examples:

```
SpeechToElement.startWebSpeech({element: targetElement, displayInterimResults: false});
SpeechToElement.startAzure({element: targetElement, region: "westus", token: "token"});
SpeechToElement.toggle("webspeech", {element: targetElement, language: "en-US"});
SpeechToElement.toggle("azure", {element: targetElement, region: "eastus", subscriptionKey: "key"});
SpeechToElement.startAzure({element: targetElement, region: 'westus', token: 'token'});
SpeechToElement.toggle('webspeech', {element: targetElement, language: 'en-US'});
SpeechToElement.toggle('azure', {element: targetElement, region: 'eastus', subscriptionKey: 'key'});
SpeechToElement.stop();
SpeechToElement.endCommandMode();
```
Expand Down Expand Up @@ -102,8 +102,8 @@ Generic options for the speech to element functionality:
Examples:

```
SpeechToElement.toggle("webspeech", {element: targetElement, translations: {hi: 'bye', Hi: 'Bye'}});
SpeechToElement.toggle("webspeech", {onResult: (text) => console.log(text)});
SpeechToElement.toggle('webspeech', {element: targetElement, translations: {hi: 'bye', Hi: 'Bye'}});
SpeechToElement.toggle('webspeech', {onResult: (text) => console.log(text)});
```

##### TextColor:
Expand All @@ -118,7 +118,7 @@ Object used to set the color for transcription result text (does not work for `i
Example:

```
SpeechToElement.toggle("webspeech", {
SpeechToElement.toggle('webspeech', {
element: targetElement, textColor: {interim: 'grey', final: 'black'}
});
```
Expand All @@ -142,13 +142,13 @@ Object used to set the phrases of commands that will control transcription and i
Example:

```
SpeechToElement.toggle("webspeech", {
SpeechToElement.toggle('webspeech', {
element: targetElement,
commands: {
pause: "pause",
resume: "resume",
removeAllText: "remove text",
commandMode: "command"
pause: 'pause',
resume: 'resume',
removeAllText: 'remove text',
commandMode: 'command'
}
});
```
Expand All @@ -165,13 +165,13 @@ Object used to configure how the command phrases are interpreted:
Example:

```
SpeechToElement.toggle("webspeech", {
SpeechToElement.toggle('webspeech', {
element: targetElement,
commands: {
removeAllText: "remove text"
"settings": {
"substrings": true,
"caseSensitive": false
removeAllText: 'remove text',
settings: {
substrings: true,
caseSensitive: false
}}
});
```
Expand All @@ -189,10 +189,10 @@ Result object for the `onPreResult` function. This can be used to control the sp
Example for a creating a custom command:

```
SpeechToElement.toggle("webspeech", {
SpeechToElement.toggle('webspeech', {
element: targetElement,
onPreResult: (text) => {
if (text.toLowerCase().includes("custom command")) {
if (text.toLowerCase().includes('custom command')) {
SpeechToElement.endCommandMode();
your custom code here
return {restart: true, removeNewText: true};
Expand All @@ -211,12 +211,12 @@ Custom options for the [Web Speech API](https://developer.mozilla.org/en-US/docs
Example:

```
SpeechToElement.toggle("webspeech", {element: targetElement, language: "en-GB"});
SpeechToElement.toggle('webspeech', {element: targetElement, language: 'en-GB'});
```

##### AzureOptions:

Options for the [Azure Cognitive Speech Services API](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-to-text). This object requires `region` and either `retrieveToken`, `subscriptionKey` or the `token` properties to be defined with it:
Options for the [Azure Cognitive Speech Services API](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-to-text). This object REQUIRES `region` and either `retrieveToken` or `subscriptionKey` or `token` properties to be defined with it:

| Name | Type | Description |
| :----------------- | :---------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -230,9 +230,14 @@ Options for the [Azure Cognitive Speech Services API](https://learn.microsoft.co
Examples:

```
SpeechToElement.toggle("azure", {element: targetElement, token: "token", language: "ja-JP"});
SpeechToElement.toggle('azure', {
element: targetElement,
region: 'eastus',
token: 'token',
language: 'ja-JP'
});
SpeechToElement.toggle("azure", {
SpeechToElement.toggle('azure', {
element: targetElement,
region: 'southeastasia',
retrieveToken: async () => {
Expand Down
6 changes: 0 additions & 6 deletions component/src/services/azure/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ export class Azure extends Speech {
this.updateElements(interimTranscript, finalTranscript, newText);
}

// WORK - huge opportunity to fix this in the repo!!!!!
// function onRecognized(sender, recognitionEventArgs) {
// var result = recognitionEventArgs.result;
// onRecognizedResult(recognitionEventArgs.result);
// }

// prettier-ignore
private onRecognized(_: Recognizer, event: SpeechRecognitionEventArgs) {
const result = event.result;
Expand Down
1 change: 0 additions & 1 deletion component/src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class Text {
return char !== undefined && char !== ' ' && char !== ' ' && char !== '\n' && char !== '';
}

// WORK - can optimize to not not have to do it multiple times
public static breakupIntoWordsArr(text: string): string[] {
return text.split(/(\W+)/);
}
Expand Down

0 comments on commit 6a59ecd

Please sign in to comment.