-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from d-i-t-a/feature/tts
Feature/tts
- Loading branch information
Showing
10 changed files
with
155 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Project: R2D2BC - Web Reader | ||
* Developers: Aferdita Muriqi | ||
* Copyright (c) 2020. DITA. All rights reserved. | ||
* Developed on behalf of: CAST (http://www.cast.org) | ||
* Licensed to: Bokbasen AS and CAST under one or more contributor license agreements. | ||
* Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. | ||
*/ | ||
|
||
import ReaderModule from "./ReaderModule"; | ||
import AnnotationModule from "./AnnotationModule"; | ||
import { IS_DEV } from ".."; | ||
import { ISelectionInfo } from "../model/Locator"; | ||
|
||
|
||
export interface TTSModuleConfig { | ||
annotationModule: AnnotationModule; | ||
} | ||
|
||
export default class TTSModule implements ReaderModule { | ||
|
||
annotationModule: AnnotationModule; | ||
synth = window.speechSynthesis | ||
|
||
initialize() { | ||
this.annotationModule.highlighter.ttsDelegate = this | ||
} | ||
|
||
speak(selectionInfo: ISelectionInfo | undefined ): any { | ||
console.log(selectionInfo.cleanText) | ||
var self = this | ||
var utterance = new SpeechSynthesisUtterance(selectionInfo.cleanText); | ||
this.synth.cancel() | ||
this.synth.speak(utterance); | ||
utterance.onend = function () { | ||
console.log("utterance ended"); | ||
self.annotationModule.highlighter.doneSpeaking() | ||
} | ||
} | ||
|
||
public static async create(config: TTSModuleConfig) { | ||
const annotations = new this( | ||
config.annotationModule, | ||
); | ||
await annotations.start(); | ||
return annotations; | ||
} | ||
|
||
public constructor(annotationModule: AnnotationModule) { | ||
this.annotationModule = annotationModule | ||
} | ||
|
||
protected async start(): Promise<void> { | ||
this.annotationModule.delegate.ttsModule = this | ||
} | ||
|
||
async stop() { | ||
if (IS_DEV) { console.log("TTS module stop")} | ||
} | ||
|
||
} |
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