0
#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 k,读取输入并播放与读取的字符串连接的 .wav 文件。问题产生于PlaySound(TEXT(sounds[k]), NULL, SND_ASYNC);. 错误读取:(IntelliSense:标识符“Lsounds”未定义)和(错误C2065:'Lsounds':未声明的标识符)。两者似乎意味着同一件事,但是,我找不到问题的根源或导致它的原因。Lsounds 是/如何未定义的,我将如何解决它?

4

2 回答 2

0

PlaySoundAPI 用于播放 WAVE 文件。您应该为 TTS 使用SAPI COM 接口:

CComPtr <ISpVoice>  cpVoice;

//Create a SAPI Voice
HRESULT hr = cpVoice.CoCreateInstance(CLSID_SpVoice);

if(SUCCEEDED(hr))
{
  cpVoice->Speak(L"Hello World",  SPF_DEFAULT, NULL);
}
于 2015-03-29T18:31:20.760 回答
0

TEXT(sounds[k])就是导致问题的原因。TEXT()是一个宏,它扩展为L后面跟着你在里面键入的内容,所以这相当于Lsounds[k],因此是错误。

于 2015-03-29T18:05:59.310 回答