Microsoft Speech SDK 5.1 text to Speech

Source: Internet
Author: User

A PCM file that saves the cost of converting text to speech

Long Cplugin14ctrl::onspeak (LPCTSTR ucontents, long Uvolume)
{
Todo:add your dispatch handler code here

CString cstr=ucontents;
AfxMessageBox (CSTR);

//com initialization:

ccomptr<ispvoice> m_cpvoice;
HRESULT hr = m_cpvoice.cocreateinstance (clsid_spvoice);

if (FAILED (:: CoInitialize (NULL)))
Return-1;

TCHAR szfilename[256]= "x:\\xx.wav";//Assuming this contains the path to the target file

Uses_conversion;
WCHAR m_szwfilename[1000];

wcscpy (M_szwfilename, t2w (szFileName));//Convert to wide string


//Set Current sampling frequency
ccomptr<ispaudio> m_ CpOutAudio1; Sound Output Interface
Spcreatedefaultobjectfromcategoryid (spcat_audioout, &m_cpoutaudio1);//Create Interface
Spstreamformat EFMT = Spsf_44khz16bitmono;
Cspstreamformat Fmt;
Fmt.assignformat (EFMT);
if (m_cpoutaudio1)
{
hr = M_cpoutaudio1->setformat (Fmt.formatid (), fmt.waveformatexptr ());
}
Else hr = E_FAIL;
if (SUCCEEDED (HR))
{
M_cpvoice->setoutput (m_cpoutaudio1, FALSE);
}

Create an output stream, bind to a WAV file
Cspstreamformat originalfmt;
Ccomqiptr<ispstream> Cpwavstream;
Ccomqiptr<ispstreamformat> Cpoldstream;
hr = M_cpvoice->getoutputstream (&cpoldstream);
if (hr = = S_OK)
{
hr = Originalfmt.assignformat (Cpoldstream);
}
Else
hr = E_FAIL;
Create a WAV file using the functions provided in Sphelper.h

if (SUCCEEDED (HR))
{
hr = Spbindtofile (M_szwfilename, Spfm_create_always, &cpwavstream,
&originalfmt.formatid (), originalfmt.waveformatexptr ());
}
if (SUCCEEDED (HR))
{
Set the output of the sound to a WAV file instead of speakers
M_cpvoice->setoutput (Cpwavstream, TRUE);
}

Sound Setting Range 0--100
M_cpvoice->setvolume (Uvolume);

Set speech speed -10---10
M_cpvoice->setrate (-1);

Start reading
BSTR BSTR = Cstr.allocsysstring ();
M_cpvoice->speak (BSTR, Spf_async | Spf_is_not_xml, 0);


Waiting for the reading to end
M_cpvoice->waituntildone (INFINITE);
Cpwavstream.release ();

Gets the current sampling frequency 44khz32-35

/*
Spstreamformat efmt;
Ccomptr<ispstreamformat> Cpstream;
HRESULT Hroutputstream = M_cpvoice->getoutputstream (&cpstream);
if (Hroutputstream = = S_OK)
{
Cspstreamformat Fmt;
hr = Fmt.assignformat (Cpstream);
if (SUCCEEDED (HR))
{
EFMT = Fmt.computeformatenum ();
}
}

CString Strint;
Strint.format ("%d", efmt);
AfxMessageBox (Strint);

*/
Reposition the output to the original stream
M_cpvoice->setoutput (Cpoldstream, FALSE);

Releasing a BSTR
SysFreeString (BSTR);


End to release resources
:: CoUninitialize ();


return 0;
}

Microsoft Speech SDK 5.1 text to Speech

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.