473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

button stop, pause, resume, exit not function when audio played.

3
I want to make my program read word by word so i use .playsync();

but why all button cannot functioning? please help me to solve this problem.

below is my code.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using mshtml;
  9. using System.Diagnostics;
  10. using System.Text.RegularExpressions;
  11. using System.Speech.Synthesis;
  12. using System.Data.OleDb;
  13. using System.Windows.Media;
  14. using System.Media;
  15.  
  16.  
  17. namespace MalayVersion
  18. {
  19.     public partial class MalayVersion : Form
  20.     {
  21.         //SpeechSynthesizer reader; //declare the object 
  22.         System.Media.SoundPlayer player = new System.Media.SoundPlayer();
  23.  
  24.  
  25.         public MalayVersion()
  26.         {
  27.             InitializeComponent();
  28.  
  29.             //this.player.LoadCompleted += new AsyncCompletedEventHandler(player_LoadCompleted);
  30.  
  31.             // ---  pronounce word from txtWord  ---
  32.             //connect to database - microsoft access  -- DONE
  33.             //looking for the words  -- DONE
  34.             //take path for the word  -- DONE
  35.             //open file (path)  -- DONE
  36.             //play audio - open file from path(database), read!  -- DONE
  37.         }
  38.  
  39.         private void MalayVersion_Load(object sender, EventArgs e)
  40.         {
  41.             btnStop.Enabled=false;
  42.             webBrowser1.Navigate(txtAddress.Text);
  43.         }
  44.  
  45.         //btnExit
  46.         private void button3_Click(object sender, EventArgs e)
  47.         {
  48.             Environment.Exit(0);
  49.         }
  50.  
  51.         private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  52.         {
  53.             System.Threading.Thread.Sleep(1000);
  54.         }
  55.  
  56.         private void btnGo_Click(object sender, EventArgs e)
  57.         {
  58.             //progressBar1.Style = ProgressBarStyle.Marquee;
  59.             //progressBar1.MarqueeAnimationSpeed = 30;
  60.             webBrowser1.Navigate(txtAddress.Text);
  61.         }
  62.  
  63.         // ----  segment the text  ----
  64.         //paragraphs to sentences : find punctuation marks   -- DONE
  65.         //sentences to words : find blank space  -- DONE
  66.         //convert everything into readable text -- DONE
  67.  
  68.         string GetTextRange()
  69.         {
  70.             if (webBrowser1.Document != null)
  71.             {
  72.                 IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2;
  73.                 if (document != null)
  74.                 {
  75.                     IHTMLBodyElement bodyElement = document.body as IHTMLBodyElement;
  76.                     if (bodyElement != null)
  77.                     {
  78.                         IHTMLTxtRange range = bodyElement.createTextRange();
  79.  
  80.                         if (range != null)
  81.                         {
  82.                             return range.text;
  83.                         }
  84.                     }
  85.                 }
  86.             }
  87.             return null;
  88.         }
  89.  
  90.         void GetSentence()
  91.         {
  92.             string source = webBrowser1.DocumentText;
  93.  
  94.             string[] stringSeparators = { "@", "<p>", "</p>", ".", ":", "\r", "\n", "\t", "?", "!", "<br>", "\"" };
  95.             string[] result;
  96.  
  97.             result = source.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
  98.  
  99.             // Return total elements of the array
  100.             int ttl = result.Length;
  101.  
  102.             for (int i = 0; i < ttl; i++)
  103.             {
  104.                 txtSentence.Text = result[i] ;
  105.                 //MessageBox.Show(result[i]);
  106.                 GetWord();
  107.             }
  108.         }
  109.  
  110.         public static string NumberToWords(int number)
  111.         {
  112.             if (number == 0)
  113.                 return "kosong";
  114.  
  115.             if (number < 0)
  116.                 return "negatif " + NumberToWords(Math.Abs(number));
  117.  
  118.             string words = "";
  119.  
  120.             if ((number / 1000000) > 0)
  121.             {
  122.                 words += NumberToWords(number / 1000000) + " juta ";
  123.                 number %= 1000000;
  124.             }
  125.  
  126.             if ((number / 1000) > 0)
  127.             {
  128.                 words += NumberToWords(number / 1000) + " ribu ";
  129.                 number %= 1000;
  130.             }
  131.  
  132.             if ((number / 100) > 0)
  133.             {
  134.                 words += NumberToWords(number / 100) + " ratus ";
  135.                 number %= 100;
  136.             }
  137.  
  138.             if (number > 0)
  139.             {
  140.                 if (words != "")
  141.                     words += "dan ";
  142.  
  143.                 var unitsMap = new[] { "kosong", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "lapan", "sembilan", "sepuluh", "sebelas", "dua belas", "tiga belas", "empat belas", "lima belas", "enam belas", "tujuh belas", "lapan belas", "sembilan belas" };
  144.                 var tensMap = new[] { "kosong", "sepuluh", "dua puluh", "tiga puluh", "empat puluh", "lima puluh", "enam puluh", "tujuh puluh", "lapan puluh", "sembilan puluh" };
  145.  
  146.                 if (number < 20)
  147.                     words += unitsMap[number];
  148.                 else
  149.                 {
  150.                     words += tensMap[number / 10];
  151.                     if ((number % 10) > 0)
  152.                         words += " " + unitsMap[number % 10];
  153.                 }
  154.             }
  155.  
  156.             return words;
  157.         }
  158.  
  159.         void GetWord()
  160.         {
  161.             string[] delimiterChars = new string[] { " " };
  162.  
  163.             string sentence;
  164.  
  165.             if (txtSentence.Text != "")
  166.             {
  167.                 sentence = txtSentence.Text;
  168.  
  169.                 string[] words = sentence.Split(delimiterChars,
  170.                      StringSplitOptions.RemoveEmptyEntries);
  171.  
  172.                  int countWord = words.Length;
  173.                 //string[] words = sentence.Split(delimiterChars);
  174.  
  175.                  for (int i = 0; i < countWord; i++)
  176.                  {
  177.                      lblWord.Text = words[i];
  178.  
  179.                      Int32 intValue;
  180.                      if (Int32.TryParse(words[i], out intValue))
  181.                      {
  182.                          int numVal = Convert.ToInt32(words[i]);
  183.                          string str = NumberToWords(numVal);
  184.  
  185.                          lblWord.Text = str;                         
  186.                          ReadWord();
  187.                      }
  188.                      else
  189.                      {
  190.                          lblWord.Text = words[i];
  191.                          //MessageBox.Show(words[i]);
  192.                          ReadWord();
  193.                      }
  194.                  }
  195.             }
  196.         }
  197.  
  198.         void ReadWord()
  199.         {
  200.             if (txtSentence.Text != "")    //if text area is not empty 
  201.             {
  202.               /*
  203.                * search word from lblWord.Text in db
  204.                * after found the word, take path for that word in path col
  205.                * open audio file
  206.                * read the word
  207.               */
  208.  
  209.                 //set up the connection string
  210.                 string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\User\Documents\Visual Studio 2013\Projects\MalayVersion\MalayDict.accdb";
  211.                 //set up the select statement
  212.                 string SelectCommand = "SELECT path FROM Word where word = '" + lblWord.Text + "'";
  213.                 //set up the connection object&nbsp;using the conn string
  214.                 OleDbConnection Connection = new OleDbConnection(ConnectionString);
  215.                 //set up the data adapter using the select statement and the connection object
  216.                 OleDbDataAdapter Adapter = new OleDbDataAdapter(SelectCommand, Connection);
  217.                 //a new empty dataset
  218.                 DataSet ds = new DataSet();
  219.                 //fill the dataset with a new datatable of all the results
  220.                 Adapter.Fill(ds, "Word");//string is the DataTable name, can be anything
  221.                 //now, let "Table" point to the datatable with our results
  222.                 DataTable Table = ds.Tables["Word"];
  223.                 //get the path into string
  224.                 String strPath = "";
  225.                 strPath = ds.Tables[0].Rows[0]["path"].ToString();
  226.  
  227.                 //System.Media.SoundPlayer player = new System.Media.SoundPlayer();
  228.                 player.SoundLocation = strPath;
  229.                 //player.LoadCompleted += new AsyncCompletedEventHandler(player_LoadCompleted);
  230.                 player.Load();
  231.                 player.PlaySync();
  232.  
  233.                 //player.Open(new Uri(strPath));
  234.                 //player.Play();
  235.  
  236.                /* reader = new SpeechSynthesizer();
  237.                 reader.Speak(lblWord.Text);
  238.                 //reader.SpeakAsync(lblWord.Text);
  239.                 reader.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(reader_SpeakCompleted); */
  240.             }
  241.         }
  242.  
  243.  
  244.         private void btnRead_Click(object sender, EventArgs e)
  245.         {
  246.             //GetTextRange();
  247.             btnStop.Enabled = true;
  248.             GetSentence();
  249.         }
  250.  
  251.         private void btnStop_Click(object sender, EventArgs e)
  252.         {
  253.             player.Stop();
  254.         }
  255.  
  256.         private void btnPause_Click(object sender, EventArgs e)
  257.         {
  258.             //player.pause();
  259.         }
  260.  
  261.     }
  262. }
  263.  
Jun 28 '15 #1
0 1830

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Øyvind Isaksen | last post by:
Hi! I have made a function calles "send()". When I click a button, I want the function to be prosessed. This is the code that I have made, but it dont work: <%function send()
7
by: deko | last post by:
I have a function with a number of long loops. While the function is running, I want to be able to click a Stop button and exit the function as quickly as possible. The abbreviated code looks...
3
by: darrel | last post by:
This might be a really dumb question, but when should/shouldn't one use the exit function command? If I have this: function() if something then do this return that else
6
by: Bhavesh1978 | last post by:
Hi Guys. im new in c programming using turbo c i have just created a box of exit button and now want to make the exit work when i use the mouse so it can close the program. does any1 here...
2
by: Carla Simeoni | last post by:
Assume I have an open Form. Then I click the "normal" window "X" icon (=Close button). How do I assign a function in Form.cs to this event ? In other words if this Form/window is closed I want to...
5
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The problem I have is when the clear form button is...
3
by: sony.m.2007 | last post by:
Hi, I’m new to ASP.NET I have written a function with a return value. If the arguments to the functions are invalid means I’m giving exit(0) Else means do some process and return a value. When...
3
by: DaveJ | last post by:
Hi, I have implemented a number of megawidget counters, and I would like them to call a function when their values change. Is this possible? So far, I have only been able to get the counters to...
8
by: Matt171717 | last post by:
Hello all, this is my first post here, so I hope I'm following all the rules here. I'm also new to using VBA in Access, so I hope this isn't a terribly dumb question. I'm almost done with my first...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.