在react-speech-kit中改变声音
我正在使用React-Speech-kit的usEspeechsynesis来读取文本时,当单击按钮时。这是我的代码:
import React, { useState } from 'react';
import { useSpeechSynthesis } from 'react-speech-kit';
function Example() {
const [value, setValue] = useState('');
const { speak } = useSpeechSynthesis();
return (
<div>
<textarea
value={value}
onChange={(event) => setValue(event.target.value)}
/>
<button onClick={() => speak({ text: value })}>Speak</button>
</div>
);
}
默认语音是一个人。我如何改变声音
I am using useSpeechSynthesis of react-speech-kit to read the text when click button. This is my code:
import React, { useState } from 'react';
import { useSpeechSynthesis } from 'react-speech-kit';
function Example() {
const [value, setValue] = useState('');
const { speak } = useSpeechSynthesis();
return (
<div>
<textarea
value={value}
onChange={(event) => setValue(event.target.value)}
/>
<button onClick={() => speak({ text: value })}>Speak</button>
</div>
);
}
The default voice is a man. How can I change the voice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了想要改变声音的同样问题。以下方法对我有用。
const {speen,voices} = usespeechsynthesis();
&lt; button onclick = {()=&gt;说话({text:value,语音:声音[1]})}&gt; speak&lt;/button&gt;
我从这个 link 。
I've encountered the same problem of wanting to change the voice. The following method worked for me.
const { speak, voices } = useSpeechSynthesis();
<button onClick={() => speak({ text: value, voice: voices[1] })}>Speak</button>
I've found the idea from this link.
在 onClick 事件期间调用的 talk 函数中,还有一个可以在文本之外传递的键值,它是“语音”
语音合成语音可在 voices 数组中使用。
希望这有帮助
In the speak function that you are calling during the onClick event there is an other key value that you can pass beyond text and it's "voice"
The speech synthesis voice is available in the voices array.
Hope this helps
当我想将默认语音更改为女性意大利口音时,我遇到了同样的问题。以下方法对我有用。
I've encountered the same problem when I want to change voice from default, to a female Italian accent. The following method worked for me.
您可以在演示中找到每个语音名称:https://mikeyparton.github. io/react-speech-kit/
你可以通过调用speechSynthesis.getVoices()来获取可用语音的列表。确保在初始化语音合成并加载语音后调用此方法,例如在 useEffect 挂钩中。
这是我使用语音名称的函数:
我的完整代码供参考:
You can find every voice name in the demo: https://mikeyparton.github.io/react-speech-kit/
You can get a list of available voices by calling speechSynthesis.getVoices(). Make sure to call this method after the speech synthesis is initialized and voices are loaded, such as within a useEffect hook.
here is my function where voice name is used:
My full code for the reference: