我已经使用以下代码实现了语音到文本和文本到语音的功能,其中我使用了语音服务小马填充工厂。对于翻译服务,我在 echo bot .Net 应用程序中使用了 Azure Translator 服务。
import React, { useMemo } from 'react';
import ReactWebChat, { createCognitiveServicesSpeechServicesPonyfillFactory, createDirectLine, createStore } from 'botframework-webchat';
import './App.css';
function App() {
const store = createStore();
const directLine = useMemo(() => createDirectLine({ secret: 'YOUR_SECRET_HERE' }), []);
const styleOptions = {
bubbleBackground: 'rgba(0, 0, 255, .1)',
bubbleFromUserBackground: 'rgba(0, 255, 0, .1)',
botAvatarInitials: 'Bot',
userAvatarInitials: 'Me',
hideUploadButton: true,
hideSendBox: false,
sendTypingIndicator: false
};
const webSpeechPonyfillFactory = createCognitiveServicesSpeechServicesPonyfillFactory({
credentials: {
region: 'REGION',
subscriptionKey: 'YOUR_KEY'
},
speechRecognitionEndpointId: 'YOUR_ENDPOINT',
});
const selectVoice = (voices, activity) => {
if (activity.locale === 'US') {
return voices.find(({ name }) => /AlvaroNeural/.test(name));
} else {
return voices.find(({ name }) => /NeerjaNeural/.test(name));
}
};
return (
<div>
<h1>Custom </h1>
<ReactWebChat
store={store}
directLine={directLine}
selectVoice={selectVoice}
webSpeechPonyfillFactory={webSpeechPonyfillFactory}
styleOptions={styleOptions}
/>
</div>
);
}
export default App;