|
1 |
| -import { Component, ViewChild, ElementRef } from '@angular/core'; |
2 |
| -import { CognitiveServices } from '@ionic-native/cognitiveservices/ngx'; |
| 1 | +import {Component, ViewChild, ElementRef} from '@angular/core'; |
| 2 | +import {CognitiveServices} from '@ionic-native/cognitiveservices/ngx'; |
3 | 3 |
|
4 | 4 |
|
5 | 5 | @Component({
|
6 |
| - selector: 'app-speechToTextTab', |
7 |
| - templateUrl: 'speechToText.page.html', |
8 |
| - styleUrls: ['speechToText.page.scss'] |
| 6 | + selector: 'app-speechToTextTab', |
| 7 | + templateUrl: 'speechToText.page.html', |
| 8 | + styleUrls: ['speechToText.page.scss'] |
9 | 9 | })
|
10 | 10 |
|
11 | 11 | export class SpeechToTextPage {
|
12 |
| - captureButtonText = 'Capture Speech'; |
13 |
| - captureButtonColor = 'primary'; |
14 |
| - capturePressed = false; |
15 |
| - |
16 |
| - constructor(private cognitiveServices: CognitiveServices) { } |
17 |
| - |
18 |
| - captureSpeechButtonClicked() { |
19 |
| - this.toggleSpeechButton(!this.capturePressed); |
20 |
| - |
21 |
| - } |
22 |
| - stopAudioCapture() { |
23 |
| - this.toggleSpeechButton(false); |
24 |
| - } |
25 |
| - |
26 |
| - toggleSpeechButton(state: boolean) { |
27 |
| - if (state) { |
28 |
| - this.capturePressed = true; |
29 |
| - this.captureButtonText = 'Stop Capture'; |
30 |
| - this.captureButtonColor = 'danger'; |
31 |
| - } else { |
32 |
| - alert('Audio capture ended'); |
33 |
| - this.capturePressed = false; |
34 |
| - this.captureButtonText = 'Capture Speech'; |
35 |
| - this.captureButtonColor = 'primary'; |
| 12 | + captureButtonText = 'Capture Speech'; |
| 13 | + captureButtonColor = 'primary'; |
| 14 | + capturePressed = false; |
| 15 | + capturedText: string[]; |
| 16 | + |
| 17 | + constructor(private cognitiveServices: CognitiveServices) { |
| 18 | + } |
| 19 | + |
| 20 | + captureSpeechButtonClicked() { |
| 21 | + this.toggleSpeechButton(!this.capturePressed); |
| 22 | + |
| 23 | + } |
| 24 | + |
| 25 | + stopAudioCapture() { |
| 26 | + this.toggleSpeechButton(false); |
| 27 | + } |
| 28 | + |
| 29 | + toggleSpeechButton(state: boolean) { |
| 30 | + if (state) { |
| 31 | + this.startListening(); |
| 32 | + this.capturePressed = true; |
| 33 | + this.captureButtonText = 'Stop Capture'; |
| 34 | + this.captureButtonColor = 'danger'; |
| 35 | + } else { |
| 36 | + this.stopListening(); |
| 37 | + this.capturePressed = false; |
| 38 | + this.captureButtonText = 'Capture Speech'; |
| 39 | + this.captureButtonColor = 'primary'; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + startListening() { |
| 44 | + this.cognitiveServices.RecognizeFromMicrophone().subscribe(results => { |
| 45 | + this.capturedText = results['result']; |
| 46 | + }, (str: any) => { |
| 47 | + alert(str); |
| 48 | + }); |
| 49 | + } |
| 50 | + |
| 51 | + stopListening() { |
| 52 | + this.cognitiveServices.StopListening(); |
36 | 53 | }
|
37 |
| - } |
38 | 54 | }
|
0 commit comments