Speech synthesis and TTS, we try to use the voice synthesis technology of Baidu but I found
One drawback is that there's no offline package that makes me uncomfortable, probably on the online version.
Reason Microsoft speech recognition technology in Windows 2000 is the default integration in system components
Maybe we don't have to look for a new speech synthesis alternative, but once the online version is offline
Only game Over,hah But one advantage is that it is easy to use for GF development
The audio stream after the No. 200-degree speech synthesis, the sister's voice sounds more comfortable if you can
To the "Kawaii" sister, will be better, but should be in the resolution of the sound
The hard feeling might be better, though speech synthesis technology has developed for so many years at least presently I
Have not yet seen what services can provide a natural sense of speaking with people, there will always be some machine
Mechanical but to talk about "Baidu speech recognition" and "optical recognition/OCR" words, I do not well-intentioned
But support the domestic heart is unchanged, but Baidu's documents are only so concise
I can conclude that it must be Baidu's developers, Hah we are not Japanese and
The Indians can't write any notes or documents, they are writing compositions can we build them?
First you need to have a Baidu account, and then to the new version of the official Baidu Voice homepage
Http://yuyin.baidu.com/fc.html
Then you will see the two different technologies above, and we choose speech synthesis technology
You can try a quick experience, which is actually implemented using the rest API, and don't tangle
We click on the use immediately, if it is the first time to use the technical services of Baidu then you need
Register the developer information once the rotten fill best lest Baidu put your information where to sell, Hah.
If you have registered your information, you will not be able to use Baidu services without creating an app.
You must create a project to "Create a new app" in the upper-right corner as shown
Then you will see the following page, feel free to fill out a valid name confirmation can apply the category
is also arbitrary choice, make so clear to Baidu what to do just use service is not sell information
When the app is created you will see the following page, then you need to click the Open service
If you do not see the service tag button, you can return to the Baidu Voice support home page
Select "Baidu Speech Synthesis" and click "Use Now"
It will prompt you to select your app and choose a sucks, then click Next
If the following page indicates success, you can also click "Create App" on the right.
Hyperlink Quick Launch Service
Well, if there is a need for Baidu help document can go to "Application Management" page click on you need
To the technical button, the following shortcut menu will pop up to select "Download SDK", or
From Baidu Voice Support home page Select "Baidu Speech Synthesis"
After clicking "Related Downloads" in the toolbar, we select the "REST API" tab, please refer to
Click Download document, but Baidu's documentation you may have seen that you might think you have not seen Hah.
Now we need to go to "get access Token" is a new thing Baidu got out
We need to go to the "app management" page and click on the "Baidu Voice recognition" technology
App, click on the "View Key" graphic button and it will appear as shown in the
We now need to extract two important parameters and API key, Secret key session
To say why it's called "secret key." I reckoned a thing that's like a cipher.
We stitch a connection to a document to query our own "Access Token".
Https://openapi.baidu.com/oauth/2.0/token?
grant_type=client_credentials&
client_id=hinqtsu6g8c6xqwfvfbwt7tm&
Client_secret=8d5dbdb1b92bf945dca42f75c9eb1a69
Explain:
Grant_type//Authorization type
client_id//API Key
Client_secret//Secret Key
Accessing the above connection in the Browse will see the text JSON code like
What we just need "access_token/access tokens" in something else straight
There is nothing too much to delete and delete.
The following began to write in C # using the Baidu Speech Synthesis Service code, first we
Need to know, Baidu speech synthesis after the output of the audio stream is MP3 not wav
In order for us to play the audio stream we need to ask for media that supports MP3 audio format
Library, but we're simply playing with its audio instead of having to make a music broadcast
The use of MCI is the most convenient and memory-saving approach
[CSharp]View Plaincopy
- Private const String lan = "zh";
- Private Const string per = "0";
- Private Const String CTP = "1";
- Private Const string spd = "3";
- Private const String pit = "6";
- Private Const String vol = "9";
- Private Const string cuid = "00-12-7b-16-74-8d";
- Private Const String tex = "Far away from the mountains and rivers quiet, love the scenery like ever" +
- "Cang He chopped down the love, life and death light paid the parting" +
- "Ramming a vein acacia into mud, mu the whole seas sad wind no trace" +
- "to the raw Sea lakeshore again, Miao Hua Mirror blizzard total Calendar";
- Private Const String tok = "24.fffd842a3fe829c873fe1c4cd0cb9c4e.2592000.1439044224.282335-6396988";
- Private Const String rest = "tex={0}&lan={1}&per={2}&ctp={3}&cuid={4}&tok={5}& Spd={6}&pit={7}&vol={8} ";
- Private const int NULL = 0, error_success = null;
- [DllImport ("WinMm.dll", CharSet = CharSet.Auto, callingconvention = callingconvention.stdcall)]
- Private static extern int mcisendstring (string lpstrcommand, string lpstrreturnstring, int Ureturnlength, int hwndcallback);
From the code above you may be wondering why or there are so many constants then you see
You will know that some friends who watch the document do not
Are you finding the same as the above constants now? It is "Baidu speech synthesis" needs
Some of the "necessary or optional" parameters, the way we use post here is mainly
Is that I'm a little too dick to use get way, although the document is get way
[CSharp]View Plaincopy
- Protected override void OnLoad (EventArgs e)
- {
- string strupdatedata = string. Format (rest, Tex, LAN, per, CTP, cuid, Tok, SPD, Pit, vol);
- HttpWebRequest req = webrequest.create ("Http://tsn.baidu.com/text2audio") as HttpWebRequest;
- Req. Method = "POST";
- Req. ContentType = "application/x-www-form-urlencoded";
- Req. ContentLength = Encoding.UTF8.GetByteCount (Strupdatedata);
- using (StreamWriter SW = New StreamWriter (req). GetRequestStream ()))
- Sw. Write (Strupdatedata);
- HttpWebResponse res = req. GetResponse () as HttpWebResponse;
- using (Stream stream = Res.) GetResponseStream ())
- {
- string strfullfilename = Application.startuppath + "/app.mp3";
- using (FileStream fs = new FileStream (Strfullfilename, Filemode.truncate | FileMode.OpenOrCreate, FileAccess.ReadWrite, Fileshare.readwrite))
- Stream. CopyTo (FS);
- if (mcisendstring (string. Format ("open \" {0}\ "Alias app", strfullfilename), null, NULL, NULL) = = ERROR_SUCCESS)
- mciSendString ("Play app", null, NULL, NULL);
- }
- }
. NET post is not the way it is, generally the most commonly used or
. NET upper layer provides HttpWebRequest, but Baidu speech recognition
Required to use UTF-8 string post, be sure to pay attention to the details here
Otherwise you will not be able to use the service provided by Baidu and return the error code to you
Presumably these details as a developer should not be committed
We write the HTTP stream returned after post to the file, but above
I said Baidu is the return of the MP3 stream, then you need to mp3 the side
Write to a file, and if you use a bass, it does not have to play in-memory
Media streaming, but the MCI way is not, if you don't understand the code
and need to use can copy my code but suggest you can read the best
Namespaces that depend on:
[CSharp]View Plaincopy
- Using System.Net;
- Using System.IO;
- Using System.Text;
- Using System.Runtime.InteropServices;
To the end of the basic, the use of Baidu speech synthesis in C # is not
It's so hard for you to imagine, you don't have to tangle with how it's used.
C # Baidu Speech synthesis