Update framework
This commit is contained in:
7
framework/tts/index.d.ts
vendored
Normal file
7
framework/tts/index.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { BaseOutput } from './outputs/base-output';
|
||||
export declare class TTS {
|
||||
private output;
|
||||
constructor(output?: BaseOutput);
|
||||
speak(text: string): void;
|
||||
stop(): void;
|
||||
}
|
12
framework/tts/index.js
Normal file
12
framework/tts/index.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { createOutput } from './output-factory';
|
||||
export class TTS {
|
||||
constructor(output = createOutput()) {
|
||||
this.output = output;
|
||||
}
|
||||
speak(text) {
|
||||
this.output.speak(text);
|
||||
}
|
||||
stop() {
|
||||
this.output.stop();
|
||||
}
|
||||
}
|
5
framework/tts/output-factory.d.ts
vendored
Normal file
5
framework/tts/output-factory.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { BaseOutput } from './outputs/base-output';
|
||||
import { AriaOutput } from './outputs/aria';
|
||||
import { WebTTSOutput } from './outputs/webtts';
|
||||
export declare function createOutput(key?: string): any;
|
||||
export { WebTTSOutput, AriaOutput, BaseOutput };
|
17
framework/tts/output-factory.js
Normal file
17
framework/tts/output-factory.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { BaseOutput } from './outputs/base-output';
|
||||
import { AriaOutput } from './outputs/aria';
|
||||
import { WebTTSOutput } from './outputs/webtts';
|
||||
export function createOutput(key = 'aria') {
|
||||
switch (key) {
|
||||
case 'aria':
|
||||
return AriaOutput;
|
||||
break;
|
||||
case 'webtts':
|
||||
return WebTTSOutput;
|
||||
break;
|
||||
default:
|
||||
return AriaOutput;
|
||||
break;
|
||||
}
|
||||
}
|
||||
export { WebTTSOutput, AriaOutput, BaseOutput };
|
11
framework/tts/outputs/aria.d.ts
vendored
Normal file
11
framework/tts/outputs/aria.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { BaseOutput } from './base-output';
|
||||
export declare class AriaOutput extends BaseOutput {
|
||||
private container;
|
||||
private speechDisplay;
|
||||
private timeout;
|
||||
constructor(options?: any);
|
||||
private init;
|
||||
speak(text: string): void;
|
||||
stop(): void;
|
||||
clearDisplay(): void;
|
||||
}
|
32
framework/tts/outputs/aria.js
Normal file
32
framework/tts/outputs/aria.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import { BaseOutput } from './base-output';
|
||||
export class AriaOutput extends BaseOutput {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
this.timeout = 100;
|
||||
this.timeout = options.timeout || 100;
|
||||
this.init();
|
||||
}
|
||||
init() {
|
||||
this.container = document.createElement('div');
|
||||
this.container.setAttribute('aria-live', 'polite');
|
||||
this.speechDisplay = document.createElement('div');
|
||||
this.speechDisplay.setAttribute('aria-live', 'polite');
|
||||
this.container.append(this.speechDisplay);
|
||||
document.body.appendChild(this.container);
|
||||
document.body.insertBefore(this.container, document.body.firstChild);
|
||||
}
|
||||
speak(text) {
|
||||
this.clearDisplay();
|
||||
const node = document.createTextNode(text);
|
||||
const para = document.createElement('p');
|
||||
para.appendChild(node);
|
||||
this.speechDisplay.appendChild(para);
|
||||
setTimeout(this.clearDisplay.bind(this), this.timeout);
|
||||
}
|
||||
stop() {
|
||||
this.clearDisplay();
|
||||
}
|
||||
clearDisplay() {
|
||||
this.speechDisplay.innerHTML = '';
|
||||
}
|
||||
}
|
5
framework/tts/outputs/base-output.d.ts
vendored
Normal file
5
framework/tts/outputs/base-output.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare class BaseOutput {
|
||||
speak(text: string): void;
|
||||
stop(): void;
|
||||
setOptions(options: any): void;
|
||||
}
|
11
framework/tts/outputs/base-output.js
Normal file
11
framework/tts/outputs/base-output.js
Normal file
@@ -0,0 +1,11 @@
|
||||
export class BaseOutput {
|
||||
speak(text) {
|
||||
return;
|
||||
}
|
||||
stop() {
|
||||
return;
|
||||
}
|
||||
setOptions(options) {
|
||||
return;
|
||||
}
|
||||
}
|
3
framework/tts/outputs/webtts.d.ts
vendored
Normal file
3
framework/tts/outputs/webtts.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { BaseOutput } from './base-output';
|
||||
export declare class WebTTSOutput extends BaseOutput {
|
||||
}
|
3
framework/tts/outputs/webtts.js
Normal file
3
framework/tts/outputs/webtts.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import { BaseOutput } from './base-output';
|
||||
export class WebTTSOutput extends BaseOutput {
|
||||
}
|
Reference in New Issue
Block a user