Function Speaker

  • TTS 语音,可以在现代浏览器直接运行。

    Parameters

    • text: string

      内容

    • lang: string = 'zh-CN'

      语言

    • volume: number = 1

      音量 [0, 1]

    • pitch: number = 1

      音高 [0, 2]

    • rate: number = 1

      速度 [0.1, 10]

    Returns {
        getInstance: (() => SpeechSynthesisUtterance);
        getVoices: (() => SpeechSynthesisVoice[]);
        setLang: ((lang: string) => void);
        setPitch: ((pitch: number) => void);
        setRate: ((rate: number) => void);
        setText: ((txt: string) => void);
        setVoice: ((voice: any) => void);
        setVolume: ((volume: number) => void);
        speak: (() => void);
        stop: (() => void);
    }

    • getInstance: (() => SpeechSynthesisUtterance)
        • (): SpeechSynthesisUtterance
        • Returns SpeechSynthesisUtterance

    • getVoices: (() => SpeechSynthesisVoice[])
        • (): SpeechSynthesisVoice[]
        • Returns SpeechSynthesisVoice[]

    • setLang: ((lang: string) => void)
        • (lang): void
        • Parameters

          • lang: string

          Returns void

    • setPitch: ((pitch: number) => void)
        • (pitch): void
        • Parameters

          • pitch: number

          Returns void

    • setRate: ((rate: number) => void)
        • (rate): void
        • Parameters

          • rate: number

          Returns void

    • setText: ((txt: string) => void)
        • (txt): void
        • Parameters

          • txt: string

          Returns void

    • setVoice: ((voice: any) => void)
        • (voice): void
        • Parameters

          • voice: any

          Returns void

    • setVolume: ((volume: number) => void)
        • (volume): void
        • Parameters

          • volume: number

          Returns void

    • speak: (() => void)
        • (): void
        • Returns void

    • stop: (() => void)
        • (): void
        • Returns void

    const mySpeaker = Speaker();
    mySpeaker.setText('你好,这是一条测试语音!hello');
    mySpeaker.speak();