コンテンツにスキップ

useSpeechSynthesis

カテゴリ
エクスポートサイズ
724 バイト
最終更新日
先週

リアクティブな SpeechSynthesis です。

対応ブラウザ

デモ




使用方法

ts
import { useSpeechSynthesis } from '@vueuse/core'

const {
  isSupported,
  isPlaying,
  status,
  voiceInfo,
  utterance,
  error,
  stop,

  toggle,
  speak,
} = useSpeechSynthesis()

オプション

以下はオプションのデフォルト値を示しており、これらは SpeechSynthesis API に直接渡されます。

ts
useSpeechSynthesis({
  lang: 'en-US',
  pitch: 1,
  rate: 1,
  volume: 1,
})

型宣言

型宣言を表示
typescript
export type UseSpeechSynthesisStatus = "init" | "play" | "pause" | "end"
export interface UseSpeechSynthesisOptions extends ConfigurableWindow {
  /**
   * Language for SpeechSynthesis
   *
   * @default 'en-US'
   */
  lang?: MaybeRefOrGetter<string>
  /**
   * Gets and sets the pitch at which the utterance will be spoken at.
   *
   * @default 1
   */
  pitch?: MaybeRefOrGetter<SpeechSynthesisUtterance["pitch"]>
  /**
   * Gets and sets the speed at which the utterance will be spoken at.
   *
   * @default 1
   */
  rate?: MaybeRefOrGetter<SpeechSynthesisUtterance["rate"]>
  /**
   * Gets and sets the voice that will be used to speak the utterance.
   */
  voice?: MaybeRef<SpeechSynthesisVoice>
  /**
   * Gets and sets the volume that the utterance will be spoken at.
   *
   * @default 1
   */
  volume?: SpeechSynthesisUtterance["volume"]
}
/**
 * Reactive SpeechSynthesis.
 *
 * @see https://vueuse.dokyumento.jp/useSpeechSynthesis
 * @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis SpeechSynthesis
 */
export declare function useSpeechSynthesis(
  text: MaybeRefOrGetter<string>,
  options?: UseSpeechSynthesisOptions,
): {
  isSupported: ComputedRef<boolean>
  isPlaying: Ref<boolean, boolean>
  status: Ref<UseSpeechSynthesisStatus, UseSpeechSynthesisStatus>
  utterance: ComputedRef<SpeechSynthesisUtterance>
  error: Ref<
    SpeechSynthesisErrorEvent | undefined,
    SpeechSynthesisErrorEvent | undefined
  >
  stop: () => void
  toggle: (value?: boolean) => void
  speak: () => void
}
export type UseSpeechSynthesisReturn = ReturnType<typeof useSpeechSynthesis>

ソース

ソースデモドキュメント

貢献者

Anthony Fu
sibbng
Anthony Fu
Jelf
wheat
Kirill Shestmintsev
糠帅傅
zwkkwz1
云游君

変更履歴

v12.0.0-beta.1 2024/11/21
0a9ed - feat!: Vue 2 のサポートを削除、バンドルを最適化、クリーンアップ (#4349)
v10.3.0 2023/07/30
ac88f - feat: pitch と rate にリアクティビティを追加 (#3205)
v10.0.0-beta.4 2023/04/13
4d757 - feat(types)!: MaybeComputedRefMaybeRefOrGetter に名前変更
10e98 - feat(toRef)!: resolveReftoRef に名前変更
v9.13.0 2023/02/18
820e2 - feat: stop 関数を追加 (#2774)

MITライセンスでリリースされています。