|
-
Nov 28th, 2009, 07:46 AM
#1
Thread Starter
Lively Member
[RESOLVED] Audio Announcement of voltage
Hello. I was wondering if will it be possible to do the following :
1) When a specific voltage is sense and is displayed on the textbox, is there any codes to allow the audio announcement of the voltage ?
(a) As voltage levels will usually be in decimal, like for example, (1.23 V) ,
it may be difficult to allow the audio announcement of exact voltages
like 1.23V?
(b) Do i have to do a pre-recording of the audios ? So that when a specific voltage is sense and displayed on the voltage level textbox, the program will call out the audio and play it out ?
If any of the above explanation is unclear, do inform me. =)
Anyways, Thanks in advance to everyone for your time in reading / responding / guidance on this.
-
Nov 28th, 2009, 08:43 AM
#2
Addicted Member
Re: Audio Announcement of voltage
One solution is to record, or find some free recordings of someone saying out every number from 0 to 9, where each number is in separate audio files. You also want a audio recording of someone saying "point" or something, to represent the ".". So when you got a voltage reading, you just loop through each number and play the correct audio file. So the reading will be like "one point two three", and not "one point twentythree".
With this method, you can play any number.
-
Nov 28th, 2009, 09:12 AM
#3
Re: Audio Announcement of voltage
If you're using Framework 3+ (Visual Studio 2008 or later), it's easy because there is a voice synthesizer built into the framework. I just tried it out for the first time, so I can tell you how to go about it.
In the Solution Explorer, right click on the project name and select Add Reference. Then select System.Speech from the .Net tab.
Now you can add these statements to your code (assuming the voltage is in TextBox1):
vb.net Code:
Using SpeakingVoltMeter As New System.Speech.Synthesis.SpeechSynthesizer
SpeakingVoltMeter.Speak(TextBox1.Text)
End Using
You can apparently select different voices and even different languages, though I'm not sure how to do that yet. In WindowsXP you get Microsoft Sam as the default voice, and he sounds just right for a speaking volt meter. In Vista I believe it's someone called Ana. The speaker handles numbers and decimals perfectly, at least in English. For example "15.123 volts" is pronounced as "fifteen point one two three vults". Well, vults is near enough .
cheers, BB
Last edited by boops boops; Nov 28th, 2009 at 09:45 AM.
-
Nov 30th, 2009, 03:14 AM
#4
Thread Starter
Lively Member
Re: Audio Announcement of voltage
Hi BB,
Once again thanks for your help on this. =)
Hmm, i tried out but the audio doesnt play out.
I doubled-clicked on the "TextBoxVoltage" and added the code you suggested into it. Or did i placed the codes in the wrong place? Or do i have to implement something else to call out the audio when required?
* textbox1 has been changed to textboxVoltage
So sorry that i may need step by step guidance from you as i'm pretty weak in programming. But i'm in the process of learning and improving from the suggestions everyone gave.
-
Nov 30th, 2009, 03:20 AM
#5
Re: Audio Announcement of voltage
what you could do is find free wav files as suggested and add them as Resources. then, in whatever event triggers the text to change in the textbox, immediately follow it with an if statement (assuming you only want to read out the voltage if a certain condition is met ie: too high or too low) and then do:
vb.net Code:
My.Computer.Audio.Play(My.Resources.VoltageSound, AudioPlayMode.WaitToComplete) 'Replace VoltageSound with whatever you named the file
-
Nov 30th, 2009, 03:25 AM
#6
Thread Starter
Lively Member
Re: Audio Announcement of voltage (RESOLVED)
Hey bb,
Kindly ignore the previous reply.
I'm able to call out the audio already! Thanks alot for your help!
I included a button, so that what it is enabled, the audio announcement will sound.
But i have a small problem.
As the numbers in the textbox will keeping varing like, for example: one moment its 2.97, the next moment its 3.02. When i click on the button, the audio may announce as 3.02, but the actual voltage shown on the textbox will be 2.90. Any idea how to solve this?
-
Nov 30th, 2009, 03:33 AM
#7
Thread Starter
Lively Member
Re: Audio Announcement of voltage
To all who responded to my thread, thanks alot for your help! =)
-
Nov 30th, 2009, 06:55 AM
#8
Re: [RESOLVED] Audio Announcement of voltage
Hi Catherine,
You can deal with a constantly varying voltage by taking an average over a short period, say the last half second. You'll need a timer to sample the voltage at intervals, for example 20 times per second. Drag one from the toolbox onto your form, and set its properties to Interval=50 (milliseconds) and Enabled=True.
Now you need somewhere to store the readings. VB.Net has various ways to store collections of data (Arrays, Lists etc.) but the best one for keeping a moving average is a Queue. Add this declaration to your form:
Code:
Dim VoltsQ As New Queue(Of Single)
Then you use the timer's Tick event to update the queue:
Code:
VoltsQ.Enqueue(volts) 'add the latest reading
If VoltsQ.Count > 10 Then VoltsQ.Dequeue() 'remove the oldest reading
The queue will hold the ten most recent values, or half a second. I suppose that will be accurate enough. Then when you click the speak button, you read out the average like this (assuming you use the synthesizer):
Code:
Dim avg As String = VoltsQ.Average.ToString("0.00")
SpeakingVoltMeter.Speak(avg)
Obviously you can play around with the Timer frequency and the length of the queue to get the kind of response you want.
cheers, BB
Last edited by boops boops; Nov 30th, 2009 at 07:03 AM.
-
Dec 1st, 2009, 02:55 AM
#9
Thread Starter
Lively Member
Re: [RESOLVED] Audio Announcement of voltage
To BB,
I've added in the code into my program, just wanna double check with you, i have to replace the following:
Using SpeakingVoltMeter As New System.Speech.Synthesis.SpeechSynthesizer
SpeakingVoltMeter.Speak(TextBoxVoltage.Text)
End Using
into
Using SpeakingVoltMeter As New System.Speech.Synthesis.SpeechSynthesizer
Dim avg As String = VoltsQ.Average.ToString("0.00")
SpeakingVoltMeter.Speak(avg)
End Using
Am i right? If i'm wrong, pls correct me =)
Unless it is wrong, this is the error that i encounter, it states that :
'Average' is not a member of 'System.Collections.Generic.Queue(Of Single)'
Hmm... ... ? So does it mean that this line
>> Dim VoltsQ As New Queue(Of Single)
is incorrect?
-
Dec 1st, 2009, 08:18 AM
#10
Re: [RESOLVED] Audio Announcement of voltage
 Originally Posted by catherine0136
To BB,
Unless it is wrong, this is the error that i encounter, it states that :
'Average' is not a member of 'System.Collections.Generic.Queue(Of Single)'
Hmm... ... ? So does it mean that this line
>> Dim VoltsQ As New Queue(Of Single)
is incorrect?
No, I expect that's because you are using Visual Studio 2005. The generics such as Queues had a lot of improvements in VS 2008 (+express), including an Average method. Of course, it's not difficult to work out an average for yourself. You could replace the line Dim Avg as String etc. by this:
Code:
Dim sum, average As Single
For Each v As Single In voltsQ
sum += v
Next
average = sum / voltsQ.Count
Dim avg As String = average.ToString("0.00")
cheers, BB
-
Dec 2nd, 2009, 03:56 AM
#11
Thread Starter
Lively Member
Re: [RESOLVED] Audio Announcement of voltage
Hi BB,
I've replaced the following :
Code:
Using SpeakingVoltMeter As New System.Speech.Synthesis.SpeechSynthesizer
Dim avg As String = VoltsQ.Average.ToString("0.00")
SpeakingVoltMeter.Speak(avg)
into the new one which you suggested, and this is what the code looks like after replacing:
Code:
Using SpeakingVoltMeter As New System.Speech.Synthesis.SpeechSynthesizer
Dim sum, average As Single
For Each v As Single In VoltsQ
sum += v
Next
average = sum / VoltsQ.Count
Dim avg As String = average.ToString("0.00")
SpeakingVoltMeter.Speak(avg)
But what i heard from the announcement is not the voltage level but something which sounds like "null" to me.
Have i replaced it wrongly?
Anyway, i was wondering , this method will take the average and announce it right?
So does it mean even if we include this coding into the program, it will not 100% accurately announce what is stated in the textbox ? Kindly correct me if i'm wrong.
[just in case u might have forgotten, the voltage level shown in the textbox varies] 
Once again, thanks for your help.
-
Dec 2nd, 2009, 06:08 AM
#12
Re: [RESOLVED] Audio Announcement of voltage
Hi Catherine.
This might be a good point for you to learn about some basic debugging techniques: how do you check what value is in the Queue and in avg while the program is running? (Answer: use a breakpoint.)
But never mind. I suggested using a Queue and averaging because I thought you were already getting a real-time stream of voltage readings, but you don't need them for reading a text box. So comment out the lines concerned, or delete them to reduce clutter.
Instead you could put this in the Click sub for your "Speak" button:
Code:
Using SpeakingVoltMeter As New System.Speech.Synthesis.SpeechSynthesizer
SpeakingVoltMeter.Speak(TextBox1.Text)
'and now show the value on the meter:
volts = Single.Parse(TextBox1.Text)
End Using
But that could do with some improvement because you always have to check what a user types into a textbox. So here's a more sophisticated version which checks if the input is valid and is in range:
Code:
Using voice As New System.Speech.Synthesis.SpeechSynthesizer
voice.Speak(TextBox1.Text)
If Not Single.TryParse(TextBox1.Text, volts) Then
voice.Speak("hey Cath, that's not a number!")
End If
If volts > maximumVolts OrElse volts < -maximumVolts Then
voice.Speak("Bah. Out of range!")
End If
End Using
Note that Single.TryParse does two jobs here: it checks if the input is numeric, and it sets the value of volts.
cheers, BB
-
Dec 2nd, 2009, 08:38 AM
#13
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|