@creativeorange/azure-text-to-speech 2.2.3 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +455 -0
- package/dist/SpeechToText.d.ts +27 -0
- package/dist/TextToSpeech.d.ts +79 -0
- package/dist/authentication.d.ts +44 -0
- package/dist/co-azure-tts.es.js +672 -209
- package/dist/co-azure-tts.umd.js +8 -8
- package/dist/main.d.ts +4 -0
- package/package.json +27 -5
- package/.eslintrc.js +0 -30
- package/index.html +0 -578
- package/nuxt/plugins/azure-speech-to-text.client.js +0 -27
- package/nuxt/plugins/azure-text-to-speech.client.js +0 -28
- package/src/SpeechToText.ts +0 -106
- package/src/TextToSpeech.ts +0 -745
- package/src/main.ts +0 -2
- package/tsconfig.json +0 -21
- package/vite.config.ts +0 -26
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {SpeechToText} from "@creativeorange/azure-text-to-speech/dist/co-azure-tts.es";
|
|
2
|
-
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
3
|
-
const speechToText = new SpeechToText(
|
|
4
|
-
'[key]',
|
|
5
|
-
'[region]',
|
|
6
|
-
'[source language]',
|
|
7
|
-
'[target language]'
|
|
8
|
-
);
|
|
9
|
-
let started = false;
|
|
10
|
-
|
|
11
|
-
nuxtApp.vueApp.mixin({
|
|
12
|
-
mounted() {
|
|
13
|
-
if (!started) {
|
|
14
|
-
setTimeout(async () => {
|
|
15
|
-
await speechToText.start();
|
|
16
|
-
}, 500);
|
|
17
|
-
started = true;
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
beforeUnmount() {
|
|
21
|
-
if (started) {
|
|
22
|
-
speechToText.stop();
|
|
23
|
-
started = false;
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {TextToSpeech} from "@creativeorange/azure-text-to-speech";
|
|
2
|
-
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
3
|
-
const textToSpeech = new TextToSpeech(
|
|
4
|
-
'[key]',
|
|
5
|
-
'[region]',
|
|
6
|
-
'[voice]',
|
|
7
|
-
1, // rate
|
|
8
|
-
1 // pitch
|
|
9
|
-
);
|
|
10
|
-
let started = false;
|
|
11
|
-
|
|
12
|
-
nuxtApp.vueApp.mixin({
|
|
13
|
-
mounted() {
|
|
14
|
-
if (!started) {
|
|
15
|
-
setTimeout(() => {
|
|
16
|
-
textToSpeech.start();
|
|
17
|
-
}, 500);
|
|
18
|
-
started = true;
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
beforeUnmount() {
|
|
22
|
-
if (started) {
|
|
23
|
-
textToSpeech.stopPlayer();
|
|
24
|
-
started = false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
});
|
package/src/SpeechToText.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SpeechTranslationConfig,
|
|
3
|
-
AudioConfig,
|
|
4
|
-
TranslationRecognizer,
|
|
5
|
-
ResultReason,
|
|
6
|
-
} from 'microsoft-cognitiveservices-speech-sdk';
|
|
7
|
-
|
|
8
|
-
export class SpeechToText {
|
|
9
|
-
key: string;
|
|
10
|
-
region: string;
|
|
11
|
-
sourceLanguage: string;
|
|
12
|
-
targetLanguage: string;
|
|
13
|
-
recognizer: TranslationRecognizer | undefined;
|
|
14
|
-
|
|
15
|
-
constructor(key: string, region: string, sourceLanguage: string, targetLanguage: string|null = null) {
|
|
16
|
-
this.key = key;
|
|
17
|
-
this.region = region;
|
|
18
|
-
this.sourceLanguage = sourceLanguage;
|
|
19
|
-
this.targetLanguage = (targetLanguage !== null) ? targetLanguage : sourceLanguage;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async start() {
|
|
23
|
-
await this.registerBindings(document);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async registerBindings(node: any) {
|
|
27
|
-
const nodes = node.childNodes;
|
|
28
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
29
|
-
if (!nodes[i]) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const currentNode = nodes[i];
|
|
34
|
-
|
|
35
|
-
if (currentNode.attributes) {
|
|
36
|
-
if (currentNode.attributes.getNamedItem('co-stt.start')) {
|
|
37
|
-
await this.handleStartModifier(currentNode, currentNode.attributes.getNamedItem('co-stt.start'));
|
|
38
|
-
} else if (currentNode.attributes.getNamedItem('co-stt.stop')) {
|
|
39
|
-
await this.handleStopModifier(currentNode, currentNode.attributes.getNamedItem('co-stt.stop'));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (currentNode.childNodes.length > 0) {
|
|
44
|
-
await this.registerBindings(currentNode);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async handleStartModifier(node: any, attr: Attr) {
|
|
50
|
-
node.addEventListener('click', async (_: any) => {
|
|
51
|
-
const speechConfig = SpeechTranslationConfig.fromSubscription(this.key, this.region);
|
|
52
|
-
speechConfig.speechRecognitionLanguage = this.sourceLanguage;
|
|
53
|
-
speechConfig.addTargetLanguage(this.targetLanguage);
|
|
54
|
-
|
|
55
|
-
const audioConfig = AudioConfig.fromDefaultMicrophoneInput();
|
|
56
|
-
|
|
57
|
-
this.recognizer = new TranslationRecognizer(speechConfig, audioConfig);
|
|
58
|
-
|
|
59
|
-
document.dispatchEvent(new CustomEvent('COAzureSTTStartedRecording', {}));
|
|
60
|
-
|
|
61
|
-
const prevResults = [];
|
|
62
|
-
this.recognizer.recognizing = (sender, event) => {
|
|
63
|
-
const result = event.result;
|
|
64
|
-
|
|
65
|
-
if (result && result.reason === ResultReason.TranslatingSpeech) {
|
|
66
|
-
const translation = result.translations.get(this.targetLanguage);
|
|
67
|
-
prevResults['result_' +result.privOffset.toString()] = translation;
|
|
68
|
-
const totalResult = Object.values(prevResults).join('. ');
|
|
69
|
-
|
|
70
|
-
const inputElement = document.getElementById(attr.value);
|
|
71
|
-
if (inputElement !== null) {
|
|
72
|
-
if (inputElement instanceof HTMLInputElement) {
|
|
73
|
-
inputElement.value = `${totalResult} `;
|
|
74
|
-
} else {
|
|
75
|
-
inputElement.innerHTML = `${totalResult} `;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
this.recognizer.startContinuousRecognitionAsync(
|
|
82
|
-
(result) => {},
|
|
83
|
-
(err) => {
|
|
84
|
-
console.log(err);
|
|
85
|
-
|
|
86
|
-
this.stop();
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async handleStopModifier(node: any, attr: Attr) {
|
|
93
|
-
node.addEventListener('click', async (_: any) => {
|
|
94
|
-
await this.stop();
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async stop() {
|
|
99
|
-
if (this.recognizer !== undefined) {
|
|
100
|
-
this.recognizer.stopContinuousRecognitionAsync();
|
|
101
|
-
this.recognizer.close();
|
|
102
|
-
this.recognizer = undefined;
|
|
103
|
-
}
|
|
104
|
-
document.dispatchEvent(new CustomEvent('COAzureSTTStoppedRecording', {}));
|
|
105
|
-
}
|
|
106
|
-
}
|