Unity3d Voice Access for PC, iOS, Android

Source: Internet
Author: User

Voice Access

Considering the mix between PC and iOS and Android, all recording formats are stored in the MP3 format and are the recommended audio files for unity.

Premise: At present the more mature speech module by the Iflytek platform provides, at present we need the function is transforms the speech to the text, therefore we only need to download the corresponding speech recognition module to be possible.

1) into the Iflytek website to download the corresponding Platform SDK, at present we only need free speech recognition can be, to create the corresponding application to download, the inside of the demo provides edge recording side translation function.

2) The PC side does not provide edge recording edge can be recorded in the PC version can be introduced into a third-party library for recording or using unity-provided microphone for recording can also

1 PC-side recording and recognition

1.1 Recording:

Method One: Unity itself has microphone recording function, stored in the AudioClip, which is the original ecological data is relatively large, we need to save the corresponding WAV file, and then turn into MP3 to the server.

To send size according to the protocol of the server, change the recorded parameters at any time, the main recording function code Microphone.start (), the general mobile is suitable for recording 10s,sample_rate (sampling rate) = 8000

's settings. MP3 recorded parameters of bitrate as far as possible to set to 16-bit (affecting the MP3 file size of the main parameters), do not understand these parameters can refer to the following links, the code will be set.

AudioClip Save As WAV reference link:

Http://www.lxway.com/812992244.htm

WAV convert to MP3 reference link:

Https://github.com/Corey-M/NAudio.Lame

Http://www.codeproject.com/Articles/5901/C-MP3-Compressor  

Http://stackoverflow.com/questions/19058530/change-format-from-wav-to-mp3-in-memory-stream-in-naudio

Method Two: The use of Naudio recording, is the use of. NET inside the recording function, while compressing MP3 also need to use the library file here to parse WAV format and so on.

1.2 Issues to note:

1.2.1 Naudio main recorded function WaveIn, when recording often need to get the size of the sound, so that the recorder can adjust the volume size. WaveIn has an event callback, according to the refresh frequency to return the corresponding file data, at this time only need to pass the corresponding data to obtain the volume, you can access the source for viewing.

http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=10182  

1.2.1 Naudio Waveout is available to play mp3, but no source play, pause, stop will not be set back state.

2, Android recording and storage, speech recognition

2.1 Currently there is no mix with pc,ios so the use of Iflytek for Edge recording translation function, the temporary use of the storage method is. AMR, if you need to mix it up we need to compress it into MP3 format, Iflytek supports recording in two ways WAV

And PCM, we only need to compress it into mp3 in unity using the same compression principle as the PC side.

Step: Need to go to the Iflytek developer website to create the application download the corresponding SDK, the source code is mainly in the Iatdemo inside

Principle: The message fly supports the voice data segmented send to identify, mainly the edge record the data to send the recognition, recording is the use of Android itself recording. The main class is Iatdemo

Question: The speechrecognizer provided by the main is generally reflected in the voice of the small, changing the volume of the phone will cause the game to change the sound at the same time, the solution: in the recording to improve the system volume, recording and then back to the original volume

2.2 PCM or WAV converted into MP3

The same is the use of lame MP3 library, the main use of the interaction between Java and C to generate the corresponding so file (mainly called Lame mp3 library method), recorded as a PCM using the so file compression can be safe easily caused by some models of the flash, not recommended, Try to use the same compression method as the PC side.

3 iOS is about the same as Android, except he has. A library, we try not to do in the Xcode project compression, iOS, PC, Android as far as possible in a unified way in the unity layer compression can be.

Unity3d Voice Access for PC, iOS, Android

Related Article

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.