如何解决如何从 Web 语音更改为 Azure 语音?
我正在尝试替换一些 web api TTS 代码:
#include "MyClass.h"
#include "TelnetClient.h"
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
MyClass::MyClass()
: telnet(NULL)
{
}
MyClass::~MyClass()
{
delete telnet;
}
bool MyClass::Connect(std::string host,std::string port)
{
// Omitted for brevety
// Create a Telnet client
delete telnet;
telnet = new TelnetClient(io_service,iterator);
// Omitted for brevety
}
class TextToSpeechService {
private utterances: Record<number,SpeechSynthesisUtterance | undefined> = {};
speak = (message: string): Promise<void> => {
return new Promise<void>((resolve) => {
const utterance = new SpeechSynthesisUtterance(message);
const Now = new Date().getMilliseconds();
this.utterances[Now] = utterance;
utterance.onend = () => {
resolve();
this.utterances[Now] = undefined;
};
并更改了这一行:
function synthesizeSpeech(message: string) {
const speechConfig = sdk.SpeechConfig.fromSubscription("my_sub_id","a_region");
const synthesizer = new sdk.SpeechSynthesizer(speechConfig);
synthesizer.speakTextAsync(
message,result => {
synthesizer.close();
return result.audioData;
},error => {
console.log(error);
synthesizer.close();
});
}
此错误:
const utterance: any = synthesizeSpeech(message);
所以看起来我的新版本没有设置 Error speaking question TypeError: Cannot set property 'onend' of undefined
。我错过了什么?
编辑:所以我认为这是由 Async 函数尚未创建任何语音引起的。我如何在 React 中处理这个问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。