-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
splincode
committed
May 4, 2023
1 parent
47dfdc6
commit 8ce633e
Showing
33 changed files
with
923 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 101 additions & 95 deletions
196
apps/demo/src/app/pages/speech/speech-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,109 @@ | ||
<label class="recognition" [tuiLabel]="label"> | ||
<ng-template #label> | ||
Speech recognition | ||
<tui-tooltip | ||
content="Say «Ok, Angular» to start recording and «Thank you, Angular» to end" | ||
></tui-tooltip> | ||
</ng-template> | ||
<ng-container *ngIf="record$ | async as result; else placeholder"> | ||
<span | ||
*ngFor="let result of result" | ||
class="transcript" | ||
[class.transcript_final]="result.isFinal" | ||
> | ||
{{ result[0].transcript }} | ||
</span> | ||
| ||
</ng-container> | ||
<ng-template #placeholder>Say «Ok, Angular»...</ng-template> | ||
</label> | ||
<tui-select [valueContent]="nameExtractor" [(ngModel)]="voice"> | ||
Voice | ||
<tui-data-list *tuiDataList> | ||
<button | ||
*ngFor="let item of voices$ | async; trackBy: voiceByName" | ||
tuiOption | ||
[value]="item" | ||
> | ||
{{ item.name }} | ||
<ng-container *ngIf="isBrowser"> | ||
<label class="recognition" [tuiLabel]="label"> | ||
<ng-template #label> | ||
Speech recognition | ||
<tui-tooltip | ||
content="Say «Ok, Angular» to start recording and «Thank you, Angular» to end" | ||
></tui-tooltip> | ||
</ng-template> | ||
<ng-container *ngIf="record$ | async as result; else placeholder"> | ||
<span | ||
*ngFor="let result of result" | ||
class="transcript" | ||
[class.transcript_final]="result.isFinal" | ||
> | ||
{{ result[0].transcript }} | ||
</span> | ||
| ||
</ng-container> | ||
<ng-template #placeholder>Say «Ok, Angular»...</ng-template> | ||
</label> | ||
<tui-select [valueContent]="nameExtractor" [(ngModel)]="voice"> | ||
Voice | ||
<tui-data-list *tuiDataList> | ||
<button | ||
*ngFor="let item of voices$ | async; trackBy: voiceByName" | ||
tuiOption | ||
[value]="item" | ||
> | ||
{{ item.name }} | ||
</button> | ||
</tui-data-list> | ||
</tui-select> | ||
<tui-text-area | ||
class="textarea" | ||
[waTextToSpeech]="text | waUtterance: options" | ||
[waTextToSpeechPaused]="paused" | ||
[(ngModel)]="text" | ||
(waTextToSpeechEnd)="onEnd()" | ||
> | ||
Text | ||
</tui-text-area> | ||
<div class="buttons"> | ||
<button tuiButton type="button" (click)="onClick()"> | ||
{{ paused ? 'Play' : 'Pause' }} | ||
</button> | ||
</tui-data-list> | ||
</tui-select> | ||
<tui-text-area | ||
class="textarea" | ||
[waTextToSpeech]="text | waUtterance: options" | ||
[waTextToSpeechPaused]="paused" | ||
[(ngModel)]="text" | ||
(waTextToSpeechEnd)="onEnd()" | ||
> | ||
Text | ||
</tui-text-area> | ||
<div class="buttons"> | ||
<button tuiButton type="button" (click)="onClick()"> | ||
{{ paused ? 'Play' : 'Pause' }} | ||
</button> | ||
Tip: say «Show sidebar» | ||
</div> | ||
Tip: say «Show sidebar» | ||
</div> | ||
|
||
<div *tuiSidebar="(open$ | async) || false"> | ||
<div class="sidebar"> | ||
<h2>More from @ng-web-apis</h2> | ||
<div *tuiSidebar="(open$ | async) || false"> | ||
<div class="sidebar"> | ||
<h2>More from @ng-web-apis</h2> | ||
|
||
<a | ||
href="https://github.com/ng-web-apis/workers" | ||
target="_blank" | ||
class="link" | ||
> | ||
<h3>Workers</h3> | ||
<img | ||
src="https://ng-web-apis.github.io/dist/assets/images/workers.svg" | ||
width="64" | ||
height="64" | ||
alt="Worker API logo" | ||
class="icon" | ||
/> | ||
</a> | ||
<a | ||
href="https://github.com/ng-web-apis/workers" | ||
target="_blank" | ||
class="link" | ||
> | ||
<h3>Workers</h3> | ||
<img | ||
src="https://ng-web-apis.github.io/dist/assets/images/workers.svg" | ||
width="64" | ||
height="64" | ||
alt="Worker API logo" | ||
class="icon" | ||
/> | ||
</a> | ||
|
||
<a | ||
href="https://github.com/ng-web-apis/canvas" | ||
target="_blank" | ||
class="link" | ||
> | ||
<h3>Canvas</h3> | ||
<img | ||
src="https://ng-web-apis.github.io/dist/assets/images/canvas.svg" | ||
width="64" | ||
height="64" | ||
alt="Worker API logo" | ||
class="icon" | ||
/> | ||
</a> | ||
<a | ||
href="https://github.com/ng-web-apis/canvas" | ||
target="_blank" | ||
class="link" | ||
> | ||
<h3>Canvas</h3> | ||
<img | ||
src="https://ng-web-apis.github.io/dist/assets/images/canvas.svg" | ||
width="64" | ||
height="64" | ||
alt="Worker API logo" | ||
class="icon" | ||
/> | ||
</a> | ||
|
||
<a | ||
href="https://github.com/ng-web-apis/audio" | ||
target="_blank" | ||
class="link" | ||
> | ||
<h3>Audio</h3> | ||
<img | ||
src="https://ng-web-apis.github.io/dist/assets/images/audio.svg" | ||
width="64" | ||
height="64" | ||
alt="Worker API logo" | ||
class="icon" | ||
/> | ||
</a> | ||
<a | ||
href="https://github.com/ng-web-apis/audio" | ||
target="_blank" | ||
class="link" | ||
> | ||
<h3>Audio</h3> | ||
<img | ||
src="https://ng-web-apis.github.io/dist/assets/images/audio.svg" | ||
width="64" | ||
height="64" | ||
alt="Worker API logo" | ||
class="icon" | ||
/> | ||
</a> | ||
|
||
<a href="https://ng-web-apis.github.io/" target="_blank" class="link"> | ||
See all | ||
</a> | ||
<a | ||
href="https://ng-web-apis.github.io/" | ||
target="_blank" | ||
class="link" | ||
> | ||
See all | ||
</a> | ||
|
||
Tip: say «Hide sidebar» when you're done | ||
Tip: say «Hide sidebar» when you're done | ||
</div> | ||
</div> | ||
</div> | ||
</ng-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {Observable, timer} from 'rxjs'; | ||
import {map} from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'app-clock', | ||
template: ` | ||
{{ date$ | async | date: 'mediumTime' }} | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ClockComponent { | ||
readonly date$: Observable<number> = timer(0, 1000).pipe(map(() => Date.now())); | ||
} |
14 changes: 14 additions & 0 deletions
14
apps/demo/src/app/pages/workers/workers-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<ng-container *ngIf="isBrowser"> | ||
<app-clock></app-clock> | ||
|
||
<div class="example"> | ||
<button (click)="workerThread.postMessage()"> | ||
Run in worker process | ||
</button> | ||
<p>Execution time: {{ workerData$ | async }}</p> | ||
</div> | ||
<div class="example"> | ||
<button (click)="emitter.next()">Run in main process</button> | ||
<p>Execution time: {{ result$ | async }}</p> | ||
</div> | ||
</ng-container> |
13 changes: 13 additions & 0 deletions
13
apps/demo/src/app/pages/workers/workers-page.component.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
:host { | ||
perspective: 150vw; | ||
user-select: none; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.example { | ||
min-width: 360px; | ||
border-top: 1px solid gainsboro; | ||
margin-top: 16px; | ||
padding-top: 16px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {ChangeDetectionStrategy, Component, Inject, PLATFORM_ID} from '@angular/core'; | ||
import {toData, WebWorker} from '@ng-web-apis/workers'; | ||
import {Subject} from 'rxjs'; | ||
import {map} from 'rxjs/operators'; | ||
import {isPlatformBrowser} from '@angular/common'; | ||
|
||
function startCompute(): number { | ||
const start = performance.now(); | ||
|
||
Array.from({length: 16000}).forEach((_, index) => | ||
Array.from({length: index}).reduce<number>((sum: number) => sum + 1, 0), | ||
); | ||
|
||
return performance.now() - start; | ||
} | ||
|
||
@Component({ | ||
selector: `workers-page`, | ||
templateUrl: `./workers-page.component.html`, | ||
styleUrls: [`./workers-page.component.less`], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class WorkersPageComponent { | ||
readonly isBrowser = isPlatformBrowser(this.platformId); | ||
readonly workerThread = WebWorker.fromFunction<void, number>(startCompute); | ||
readonly workerData$ = this.workerThread.pipe(toData()); | ||
readonly emitter: Subject<void> = new Subject(); | ||
readonly result$ = this.emitter.pipe(map(startCompute)); | ||
|
||
constructor(@Inject(PLATFORM_ID) readonly platformId: Record<any, any>) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {WorkersPageComponent} from './workers-page.component'; | ||
import {RouterModule} from '@angular/router'; | ||
import {CommonModule} from '@angular/common'; | ||
import {WorkerModule} from '@ng-web-apis/workers'; | ||
import {ClockComponent} from './clock.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
WorkerModule, | ||
RouterModule.forChild([{path: '', component: WorkersPageComponent}]), | ||
], | ||
declarations: [WorkersPageComponent, ClockComponent], | ||
}) | ||
export class WorkersPageModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.