#include <windows.h>
#include <mmsystem.h>
#include <iostream>
#include <string.h>
#include <fstream>
char *sounds[] = {"d.wav","ai.wav","v.wav","i.wav"};
int main()
{
char input[20];
int k;
int i = 0;
std::cin >> input;
while (input[i])
{
k = input[i] - 'a';
PlaySound(TEXT(sounds[k]), NULL, SND_ASYNC);
}
system("pause");
}
为了制作一个文字到演讲的程序,我遇到了这个问题。
int,读取输入并播放与所读取的字符串连接的.wav文件。这个问题来自于PlaySound(TEXT(sounds[k]), NULL, SND_ASYNC);
。错误的内容为:(IntelliSense:标识符“”是未定义的)和(error C2065:‘and’:未声明的标识符)。这两者的意思似乎是相同的,然而,我找不到问题的根源或原因。L听起来是如何定义的?我将如何修复它?
发布于 2015-03-29 18:05:59
是TEXT(sounds[k])
引起了这个问题。TEXT()
是一个宏,它扩展到L
,后面跟着您在里面键入的内容,所以这相当于Lsounds[k]
,因此出现了错误。
发布于 2015-03-29 18:31:20
PlaySound
API用于播放波形文件。您应该使用SAPI COM接口进行TTS:
CComPtr <ISpVoice> cpVoice;
//Create a SAPI Voice
HRESULT hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
if(SUCCEEDED(hr))
{
cpVoice->Speak(L"Hello World", SPF_DEFAULT, NULL);
}
https://stackoverflow.com/questions/29332786
复制相似问题