-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Open Response): Add SpeechToText transcription support (#1642)
Co-authored-by: Jonathan Lim-Breitbart <[email protected]>
- Loading branch information
1 parent
133938b
commit e28b7e3
Showing
14 changed files
with
4,582 additions
and
2,521 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
46 changes: 46 additions & 0 deletions
46
src/assets/wise5/components/openResponse/speech-to-text/speech-to-text.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,46 @@ | ||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px"> | ||
<span class="mat-caption" i18n>Speak to add to your response:</span> | ||
<button | ||
mat-stroked-button | ||
[matMenuTriggerFor]="languageSelect" | ||
[disabled]="recording()" | ||
matTooltip="Select language" | ||
i18n-mat-tooltip | ||
> | ||
<mat-icon>translate</mat-icon> | ||
<span *ngIf="selectedLanguage()">{{ selectedLanguage().name }}</span> | ||
</button> | ||
<mat-menu #languageSelect="matMenu"> | ||
<button | ||
*ngFor="let language of languages" | ||
[value]="language" | ||
mat-menu-item | ||
(click)="changeLanguage(language)" | ||
[class]="{ primary: language.code === selectedLanguage().code }" | ||
> | ||
{{ language.name }} | ||
</button> | ||
</mat-menu> | ||
<button | ||
*ngIf="!(recording() && recordingRequester)" | ||
[disabled]="recording()" | ||
mat-icon-button | ||
color="primary" | ||
(click)="toggleRecording()" | ||
matTooltip="Record voice" | ||
i18n-mat-tooltip | ||
> | ||
<mat-icon>mic</mat-icon> | ||
</button> | ||
<ng-container *ngIf="recording() && recordingRequester"> | ||
<button | ||
mat-icon-button | ||
(click)="toggleRecording()" | ||
matTooltip="Stop recording" | ||
i18n-mat-tooltip | ||
> | ||
<mat-icon color="warn">stop_circle</mat-icon> | ||
</button> | ||
<span class="mat-caption text-secondary" i18n>Recording...</span> | ||
</ng-container> | ||
</div> |
Empty file.
35 changes: 35 additions & 0 deletions
35
src/assets/wise5/components/openResponse/speech-to-text/speech-to-text.component.spec.ts
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,35 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { SpeechToTextComponent } from './speech-to-text.component'; | ||
import { TranscribeService } from '../../../services/transcribeService'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { ProjectService } from '../../../services/projectService'; | ||
import { ConfigService } from '../../../services/configService'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
|
||
describe('SpeechToTextComponent', () => { | ||
let component: SpeechToTextComponent; | ||
let fixture: ComponentFixture<SpeechToTextComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [BrowserAnimationsModule, HttpClientTestingModule, SpeechToTextComponent], | ||
providers: [ | ||
ConfigService, | ||
{ | ||
provide: ProjectService, | ||
useValue: { | ||
project: { speechToText: { defaultLanguage: 'en-US', supportedLanguages: [] } } | ||
} | ||
}, | ||
TranscribeService | ||
] | ||
}); | ||
fixture = TestBed.createComponent(SpeechToTextComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
74 changes: 74 additions & 0 deletions
74
src/assets/wise5/components/openResponse/speech-to-text/speech-to-text.component.ts
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,74 @@ | ||
import { Component, EventEmitter, Output, Signal } from '@angular/core'; | ||
import { Language, TranscribeService } from '../../../services/transcribeService'; | ||
import { MatFormFieldModule } from '@angular/material/form-field'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { CommonModule } from '@angular/common'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { MatTooltipModule } from '@angular/material/tooltip'; | ||
import { MatMenuModule } from '@angular/material/menu'; | ||
import { FlexLayoutModule } from '@angular/flex-layout'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'speech-to-text', | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
FlexLayoutModule, | ||
MatButtonModule, | ||
MatFormFieldModule, | ||
MatIconModule, | ||
MatMenuModule, | ||
MatTooltipModule | ||
], | ||
templateUrl: './speech-to-text.component.html', | ||
styleUrls: ['./speech-to-text.component.scss'] | ||
}) | ||
export class SpeechToTextComponent { | ||
protected languages: Language[] = this.transcribeService.languages; | ||
@Output() newTextEvent: EventEmitter<string> = new EventEmitter<string>(); | ||
protected recording: Signal<boolean> = this.transcribeService.recording; | ||
protected recordingRequester = false; | ||
protected selectedLanguage: Signal<Language> = this.transcribeService.selectedLanguage; | ||
|
||
constructor(private transcribeService: TranscribeService) {} | ||
|
||
ngOnDestroy(): void { | ||
this.stopRecording(); | ||
} | ||
|
||
protected toggleRecording(): void { | ||
if (!this.recording()) { | ||
this.startRecording(); | ||
} else { | ||
this.stopRecording(); | ||
} | ||
} | ||
|
||
protected changeLanguage(language: Language): void { | ||
this.transcribeService.setSelectedLanguage(language); | ||
} | ||
|
||
private async startRecording(): Promise<void> { | ||
try { | ||
this.recordingRequester = true; | ||
await this.transcribeService.startRecording( | ||
this.selectedLanguage().code, | ||
this.processTranscriptionText.bind(this) | ||
); | ||
} catch (error) { | ||
alert($localize`An error occurred while recording: ${error.message}`); | ||
this.stopRecording(); | ||
} | ||
} | ||
|
||
private stopRecording(): void { | ||
this.transcribeService.stopRecording(); | ||
this.recordingRequester = false; | ||
} | ||
|
||
private processTranscriptionText(text: string): void { | ||
this.newTextEvent.emit(text); | ||
} | ||
} |
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.