Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sound Question

Status
Not open for further replies.

xma

Technical User
Dec 7, 2006
14
US
I am trying to have the "Speech" after the "SoundRec" but it always says the "Speech" first.
I don't understand why it does not work.
Thank you for your help.
dhh

Sub Macro1()
'
Range("A1").Select
ActiveSheet.Shapes("object 1").Select
Selection.Verb Verb:=xlPrimary

Application.Speech.Speak "Hello and how are you today"

End Sub
 
Could you elaborate a little more?

--

"If to err is human, then I must be some kind of human!" -Me
 
Thank you for your help.
In this sample I have it speaking something that I have talked into a microphone and it is a EMBED("SoundRec","")
file. Then I have it doing a normal speech code
Application.Speech.Speak "Hello and how are you today" after
it does the microphone speech. This is all in the VBA macro code that when I click the button that it should do the
microphone speech and then the Application.Speech.Speak second.
My problem is that is does the Application.Speech.Speak FIRST then the microphone speech SECOND.
I am doing something wrong or something is missing.
Thank you for your help.


ActiveSheet.Shapes("object 1").Select
Selection.Verb Verb:=xlPrimary
 
Hmm, well, have you tried storing the call to each portion in separate functions or procedures, and then calling them from the button procedure in the order you want? Maybe that would fix the ordering...

For instance:
Code:
Public Sub SoundRec()
   'Do whatever here
End Sub

Public Sub Speak()
   'Do whatever here
End Sub

Public Sub MyButtonPusher()
   SoundRec
   Speak
End Sub

Does that make enough sense?

--

"If to err is human, then I must be some kind of human!" -Me
 
Thank you for your help.
I am not very good with VBA so my questions will be dumb.
You had "Public" listed and I have the code in
VBAProject (PERSONAL.XLS) Module1.
and this is linked to a control button on the Excel sheet.
I don't know how to link the more then one "procedures"
to a control button.

Sub Macro1()

Public Sub SoundRec()
ActiveSheet.Shapes("object 1").Select
Selection.Verb Verb:=xlPrimary
End Sub

Public Sub Speak()
Application.Speech.Speak "Hello and how are you today"
End Sub


If this was all in "Macro1" and that was the link from the button. Is this what you mean? Will this link them togeather?
Thank you for your help.


 
Don't know much about Speak, but playing of sounds is most likely asynchronous, i.e. you set it going and it returns straight away, while the sound continues to play in the background.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Steve - Thank you for your help.
How do I link them togeather?
I can link them to the macro button one by one but not togeather.

Public Sub SoundRec()
ActiveSheet.Shapes("object 1").Select
Selection.Verb Verb:=xlPrimary

End Sub

Public Sub Speak()
Application.Speech.Speak "Hello and how are you today"
End Sub
 
xma,

In VBA, you can call any Sub or Function that is labeled Publich from within another Sub or Function.

So, the 2 Public Subs would be written in one of the modules within PERSONAL.XLS. Then, in whatever macro you recorded to link to a button, you can call those two other subs (Sub-Procedures), just the way I typed.

Try the code as I typed it, and the one that says "MyButtonPusher" replace with whatever you have connected to your button - it's that simple. Of course, you'll want the details of each procedure put within each procedure.

Let me know whether this makes sense to you or not, and let me know WHAT does not make sense if it does not. [wink]

--

"If to err is human, then I must be some kind of human!" -Me
 
Um, oops... I meant Public - not Publich... Oh well
[blush]

Now where's that undo button?! [LOL]

--

"If to err is human, then I must be some kind of human!" -Me
 
kjv1611 - Thanks for your help. I finaly understand what you are telling me and set up the macro button to the
"MyButtonPusher" macro. It worked like you said and linked them both togeather but it STILL done the "Speak" first and the "SoundRec" second. The "Speak" is set up to run second but still runs first?
Thank you for your help.

Public Sub MyButtonPusher()
SoundRec
Speak
End Sub
 
Hmmm, I can't help but wonder - since you are including the audio files within the excel worksheet itself (or so it seems) - that it has to do with the way Excel apparently handles things.

This won't be the "programming" answer to your problem, but it may solve your problem for now, at least.

You could use an audio editor and just put both files together into one audio file, and then only have one audio file to deal with.

Here's what I mean:

Download the freeware audio editor, Audacity here:

Then, if your sound files are MP3 files, or if you think you'll ever want to tinker with any MP3 files, then you'll need to download the MP3 encoder here (just pick a download site from the list):

Make sure you download both files in a place where you can find them.

Next, run the Audacity installation, and it should ask you for where the MP3 codec is, unless it finds it automatically. Tell Audacity where the enoder file is, complete the installation.

When you first open Audacity, you may have some tips or something - you can read or not read, it's up to you. The most basic controls are pretty intuitive.

Here's what you do. In Audacity, open the SoundRec file. Then, open the Speak file. This should open 2 separate sessions of Audacity.

Next, copy the entire selection from the Speak file (You can use <Ctrl> + <A> for selecting all, if I remember correctly, or you can hit your home key when the file is selected, and then press <Shift> + <End>. Once you've selected it, just copy it just like you would with most programs - <Ctrl> + <C> should work fine.

Next select the SoundRec file within the other instance of Audigy, and press your <End> button. Then Press <Ctrl>+<V> to paste the Speak file at the end of the SounRec file.

Those instructions are assuming you have enough space as desired at the end of the first, or the beginning of the second file. If not, you'll want to insert some silence. Here's how:

"Generate" menu->
"Silence"->
Specify the length of time.
Press "OK".

Or, if you already pasted the one file behind the other, just do the same between the two files.

Then, save the filename to whatever you choose, and insert the new file into your workbok.

**Note: To save the file, you have to do it a little different in Audacity. You do it this way:
File->
Export As->
Choose the format of preference->
Save the file.

In your VBA code, at this point, you can just refer to the one file, and don't worry about the order, b/c the VBA code will not be able to play one file out of order if it is already recorded that way - as far as I know.

Let us know if you end up going this route, or else what you end up doing.


--

"If to err is human, then I must be some kind of human!" -Me
 
kjv1611 - Thank you for your help. I don't consider myself experienced enough to do what you suggested on the downloads.
I would probably mess the system and then I would end up with less then I have. I will just Record what I want to say which is the same thing as the Speech with out the computer voice. I can run one Object after the another-
(Wait a minute I JUST tried to do that and it plays both recording at once) so I thought it would work.)
I thought I would be able to play one after the other.
Thanks for all of your help and knowledge.
 
Sure thing.

But, just to mention: You shouldn't have any system stability programs from running Audacity. I've ran it on several different machines with differing specs with no problems at all. I've run it on at least as slow as a 900mhz processor, and as fast as a 3 ghz+. I've run it at home, church, work, and maybe someone else's house. It looks and sounds like a lot more than it actually is! :)

If you don't get this working through VBA or whatever, and don't want to do the audio editing, but would like some help, I wouldn't mind putting it together for you. I doubt it would take more than ten minutes for me to do it.

Just let me know, and either post them on a web site, or you can send them to me. Just let me know.

--

"If to err is human, then I must be some kind of human!" -Me
 
kjv1611 - Thank you very much for your help and the offer to set it up for me. That is such a kind and generous gesture. I am going to try some other methods in the process of trying to learn more about VBA and it's logic.
If I run into a brick wall I will ask you for your help.
Thank you again for your help.
 
From Excel2003 VBA Help;
expression.Speak(Text, SpeakAsync, SpeakXML, Purge)

expression Required. An expression that returns a Speech object.

Text Required String. The text to be spoken.

SpeakAsync Optional Variant. True will cause the Text to be spoken asynchronously (the method will not wait of the Text to be spoken). False will cause theText to be spoken synchronously (the method waits for the Text to be spoken before continuing). The default is False.

So try using the optional variant SpeakAsync set to False.

Along the lines of
Code:
Sub Macro1()
 '
    Range("A1").Select
'    ActiveSheet.Shapes("object 1").Select
 '   Selection.Verb Verb:=xlPrimary
     
    Application.Speech.Speak _
        Text:="Hello and how are you today", _
        SpeakAsync:=False
End Sub

If Steve was right about the root of your problem then this should fix it.


Gavin
 
Gavona - Thank you very much for your help.
I tried your code and it still acts as before but with one difference. The speech does not run at the same time as the recording like before. The "SpeakAsync:=False" did cause it be seperated. I also tried "SpeakAsync:=True" to see what would happen and it acted the same as "False" command which surprised me. After reading the detail that you provided on "expression.Speak" I thought it would work and do the Recording first and speak second. I also reversed the order to speak first and record second and it also acted the same.

Thank you very much for your code and help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top