Cra*_*tis 5 window interface speech-synthesis angular2-services angular
我正在尝试使用speechSynthesis http://blog.teamtreehouse.com/getting-started-speech-synthesis-api
首先,我使用界面扩展了窗口:
window.interface.ts
export interface IWindow extends Window {
webkitSpeechRecognition: any;
speechSynthesis: any;
}
Run Code Online (Sandbox Code Playgroud)
接下来我做了一个窗口服务:
window.service.ts
import { Injectable } from '@angular/core';
import { IWindow } from '../interfaces/window-interface';
function _window() : IWindow {
return window;
}
@Injectable()
export class WindowService {
get nativeWindow() : any {
return _window();
}
}
Run Code Online (Sandbox Code Playgroud)
现在在组件中,我正在尝试实现它......没有成功..
app.component
import { Component, OnInit, ViewChild } from '@angular/core';
import { WindowService } from '../../providers/window.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['.app.component.scss']
})
export class AppComponent implements OnInit {
constructor(private _router: Router, private _window: WindowService ) { }
sayIt() {
var utterance = new SpeechSynthesisUtterance('Hello World');
this._window.speechSynthesis.speak(utterance);
}
}
Run Code Online (Sandbox Code Playgroud)
TS错误:
Cannot find name 'SpeechSynthesisUtterance'.)
Property 'speechSynthesis' does not exist on type 'WindowService'.)
Run Code Online (Sandbox Code Playgroud)
我还将这篇文章用于语音识别作为参考:Angular2:Web Speech API - 语音识别
仍然得到错误 - 属性'speechSynthesis'在类型'Window'上不存在
| 归档时间: |
|
| 查看次数: |
1946 次 |
| 最近记录: |