Categories
Uncategorized

The amount of digital voice broadcast

Recently doing a voice broadcast feature, starting with Speech to do. Feeling the results were good, you can direct text to speech, then broadcast it. But back then tested on the machine, we find that play is English, after a search found the need to support voice. There may be some system features the entire speech may be castrated, I can only think another way.

The other from the idea: In fact, only changes in the numbers, other spoken word is generally fixed. Then we can put 0-9 record into 10 separate wav file, then the amount of digital split into char, play the corresponding file not to OK it! Just do it:

First need to record file out, specific codes are as follows:

Task.Run(() =>
            {
                decimal payAmt = 123.56M;
                string payString = payAmt.ToString("F2");
                //

Fixed voice playback prefix "Dragon payments receivable"

using (SoundPlayer simpleSound = new SoundPlayer($"{Application.StartupPath}\\auido\\ccb.wav")) { simpleSound.Play(); //

Here we need to wait a specific time for the length of the audio file

System.Threading.Thread.Sleep(1450); foreach (var item in payString.ToArray()) { //

Play specific figures

simpleSound.SoundLocation = $"{Application.StartupPath}\\auido\\{item}.wav"; simpleSound.Play(); System.Threading.Thread.Sleep(400); } //

Play yuan

simpleSound.SoundLocation = $"{Application.StartupPath}\\auido\\yuan.wav"; simpleSound.Play(); } });

Seems to function has been achieved, but it sounds a little dull feeling like paper, but the first so be it. Submitted to the test, and the test came back saying that the unit does not sound how ah, can add units yet. Ok! ! ! can.

Function code began to realize the digital broadcast plus units, the first section of the digital-to-find characters of text under the reference, in fact, almost logical, then slightly modified on OK, the idea is still the same, to record voice files, need to increase the voice unit file: Shibaiqianwan

Then you need to convert the digital Tostring ( “F2”), do not turn here N2, otherwise there will be a comma-separated, I am here only designed to support the broadcast of less than one million.

Directly on the code

public void PayAuido(decimal payMoney)
        { 
            if (payMoney >= 100000000 || payMoney == 0)
            {
                return;
            }
            Task.Run(() =>
            {
                List<string> payAuidoUrls = new List<string>();
                string payString = payMoney.ToString("F2");
                //

If less than 11 bits, zero padding

if (payString.Length < 11) { payString = payString.PadLeft(11, '0'); } string payWan = payString.Substring(0, 4);//

Get 'Wan' unit

string payYuan = payString.Substring(4, 4);//

To obtain 'element' means

string payNum = payString.Substring(9, 2);//取得小数部分 //

Processing Wan

List<string> payAuidoUrlsWan = Convert(payWan); if (payAuidoUrlsWan.Count > 0) { payAuidoUrlsWan.Add($"{Application.StartupPath}\\auido\\wan.wav"); } //

Processing Elements

List<string> payAuidoUrlsYuan = Convert(payYuan); //

Yuan first character is a 'zero'

if (payAuidoUrlsWan.Count > 0 && payAuidoUrlsYuan.Count > 0 && payString[4] == '0') { payAuidoUrlsWan.Add($"{Application.StartupPath}\\auido\\0.wav"); } payAuidoUrls.AddRange(payAuidoUrlsWan); payAuidoUrls.AddRange(payAuidoUrlsYuan); //

Deal with decimal places

if (payNum != "00") { //

If only fractional, then add the 'zero'

if (payAuidoUrls.Count == 0) { payAuidoUrls.Add($"{Application.StartupPath}\\auido\\0.wav"); } payAuidoUrls.Add($"{Application.StartupPath}\\auido\\..wav"); payAuidoUrls.Add($"{Application.StartupPath}\\auido\\{payNum[0]}.wav"); //

If the last digit is 'zero', you do not need broadcast

if (payNum[1] != '0') { payAuidoUrls.Add($"{Application.StartupPath}\\auido\\{payNum[1]}.wav"); } } //

Adding yuan

payAuidoUrls.Add($"{Application.StartupPath}\\auido\\yuan.wav"); //

Play "dragon payments receivable"

using (SoundPlayer simpleSound = new SoundPlayer($"{Application.StartupPath}\\auido\\ccb.wav")) { simpleSound.Play(); System.Threading.Thread.Sleep(1450); foreach (string payAuidoUrl in payAuidoUrls) { //

Each digital player

simpleSound.SoundLocation = payAuidoUrl; simpleSound.Play(); System.Threading.Thread.Sleep(400); } } }); } /// /// 每四位数转换一次 /// ///

Current conversion amount

/// public List<string> Convert(string payValue) { List<string> payAuidos = new List<string>(); //

If four zeros, you do not need broadcast

if (payValue == "0000") { return payAuidos; } char tmp0 = payValue[0]; char tmp1 = payValue[1]; char tmp2 = payValue[2]; char tmp3 = payValue[3]; //

One thousand

if (tmp0 != '0') { payAuidos.Add($"{Application.StartupPath}\\auido\\{tmp0}.wav"); payAuidos.Add($"{Application.StartupPath}\\auido\\qian.wav"); } else { payAuidos.Add($"{Application.StartupPath}\\auido\\0.wav"); } //

hundreds

if (tmp1 != '0') { payAuidos.Add($"{Application.StartupPath}\\auido\\{tmp1}.wav"); payAuidos.Add($"{Application.StartupPath}\\auido\\bai.wav"); } else { //

Just add a zero

if (tmp0 != '0') { payAuidos.Add($"{Application.StartupPath}\\auido\\0.wav"); } } //

Ten

if (tmp2 != '0') { payAuidos.Add($"{Application.StartupPath}\\auido\\{tmp2}.wav"); payAuidos.Add($"{Application.StartupPath}\\auido\\shi.wav"); } else { //

Just add a zero

if (tmp1 != '0') { payAuidos.Add($"{Application.StartupPath}\\auido\\0.wav"); } } //

Bit

if (tmp3 != '0') { payAuidos.Add($"{Application.StartupPath}\\auido\\{tmp3}.wav"); } //

If the first audio is zero, then removed

if (payAuidos[0].Contains("0.wav")) { payAuidos.RemoveAt(0); } //

If the last audio zero, then removed

if (payAuidos[payAuidos.Count - 1].Contains("0.wav")) { payAuidos.RemoveAt(payAuidos.Count - 1); } return payAuidos; }

Digital input, either converted to voice broadcast, in fact, the idea is very simple, is to put each digit and units corresponding to the audio file continuous play out. DEMO Download

Leave a Reply