Play a wav file over phone line

I am workig on a little demo oriject
i am dialiing a specific telephone number, now when the user picks up the phone, i need to play a wav file so the user on the ohone hears te wav file.

is there a way to do this


Who is Participating?
inthedarkConnect With a Mentor Commented:
Have you found your way to the TAPI documentation yet?

If you subscribe to the MSDN Microsoft send you about a million CDs each year one of them is the Windows SDK which includes the documentation for TAPI.

You will find some code snippets here:
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

CraigLazarAuthor Commented:
thanx guys
i will have a good look

CraigLazarAuthor Commented:
Hi Guys
thanx for the input, i have had a brief look at the urls thnax , do any of u guiys maybe have sample code or anything, i am not to clued up the the Tapi functions and calls

CraigLazarAuthor Commented:
Hi there intheDark
I went to the url u gave me last, i am trying to find the TAPI30 sdk, i am running win 2000, anyway your url said i must go to the micrisift site under telephony and download the TAPI30 sdk, but i could not find it,
do u perhaps know where i could find it ?


It looks like they have moved it. I posted a question to Microsoft to see where they put it.
The TAPI SDK is included in the core SDK download:

CraigLazarAuthor Commented:
Thanx allot

I will check it this weekend

have a good one

I hope yo have a fast link its a 250M download
CraigLazarAuthor Commented:
hi inthedark
sorry i have not gotton back to u sooner,
got the day of for the next 2 days, so i can sit sown and spend some time on it


Have you looked at a toolkit to make this much easier for you?  With a good one, you could basically write this much code and get what you want:

enable device
go off hook
ondialtone, dial number
open wavefile
play wave file

TeleTools just upgraded to v3.7 with pretty sophisticated wave tools with ffw, rewind, pause, play from a certain point, etc.  Depending on how big or small your project is, you might want to look at having the hard work done for you and avoiding TAPI and API stuff yourself.

Hi I4m also working on a small project like you and I
think this code will help you...

If you don4t have the Telephony control in your code maybe you need to install the Microsoft Speech SDK 4.0 and after that you need to add the component to a form on your code.

After that create a wav file of 8 Khz,8 bits called msg9.wav and paste this code on a form:

'This is a very simple answering machine.
'It just takes a message and writes it to a wave file in a subdirectory of the application directory.
'You can just double click on the messages and they will be played by the system sound player.

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
         (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Private Sub ViewDirectory()
'This function simply causes the Explorer to display the Messages directory (and creates it if needed),
'so each time a new message is recorded, an icon appears that can be double clicked on.
'First we try command as if we are in windows 9x, and if that doesn't work, try NT's cmd function.
On Error Resume Next
Dim slash As String
If Right(App.Path, 1) = "\" Then
    slash = ""
    slash = "\"
End If
    mdir = App.Path + slash + "Messages"
    MkDir mdir
    ChDrive mdir
    ChDir mdir
    Shell " /c start .", vbMinimizedNoFocus
    Shell "cmd /c start .", vbMinimizedNoFocus
End Sub

Private Sub Command1_Click()

    phone1.Initialized = 1 'run on emulator

End Sub

Private Sub Command2_Click()

   phone1.Initialized = 2 'run on real phone

End Sub

Private Sub Form_Load()
End Sub

Private Sub phone1_DoPhoneCall(ByVal lineID As Long)
'This function gets called each time the phone is answered, for each phone line.
'Because Telephony supports multiple phone lines, this function may be called simultaneously
'several times, each version (identified by lineID) running on a different thread.
Dim result As Long
Dim size As Long
Dim wave As Long
Dim wavefile() As Byte
Dim filename As String

On Error Resume Next
    size = 0

    'this line causes a recorded wave file to be used in place of the text wherever it is spoken.
    '(if you comment out this line, the text-to-speech engine would be used instead)
    'This feature exists so you can prototype your program with text-to-speech, then use
    'the wave list editor to do recordings of the string.  See the docs for more details.
    phone1.WaveAddFromListString lineID, "[FromFile]" + vbNewLine + App.Path + _
        "\msg9.wav=Hi. We can't come to the phone right now. Please leave a message at the beep."

    'this is the heart of the program.  The prompts are spoken (or played if the waveadd worked),
    'and the callers message is stored in wave.  See the docs for definitions of the settings used.
    'phone1.RecordFromString lineID, "[Prompts]" + vbNewLine + _
    '                            "Main=Hi. We can't come to the phone right now. Please leave a message at the beep." + vbNewLine + _
    '                            "[Settings]" + vbNewLine + _
    '                            "BetweenUtt=10000" + vbNewLine + _
    '                            "InitialBuf=30000" + vbNewLine + _
    '                            "ReallocBuf=30000" + vbNewLine + _
    '                            "MaxBuf=300000" + vbNewLine + _
    '                            "NoAnswerTime=10" + vbNewLine _
    '                            , result, wave, size
    phone1.ExtensionFromString lineID, "[Prompts]" + vbNewLine + _
                                "Main=Hi. We can't come to the phone right now. Please leave a message at the beep." + vbNewLine + _
                                "[Settings]" + vbNewLine + _
                                "BetweenUtt=10000" + vbNewLine + _
                                "InitialBuf=30000" + vbNewLine + _
                                "ReallocBuf=30000" + vbNewLine + _
                                "MaxBuf=300000" + vbNewLine + _
                                "NoAnswerTime=10" + vbNewLine _
                                , result, "test"
    If (size <> 0) Then
        'The following "casts" the wave to an array (by making a copy of it) so we can save it out to disk.
        ReDim wavefile(size)
        CopyMemory wavefile(0), ByVal wave, size
        'free the wave as soon as possible so we dont pig up memory
        phone1.FreeWave wave
        'use the date and time as the filename, and put into the Messages directory
        filename = App.Path + "\Messages" + "\Message left at " + Format(Now, "hh mm ss AMPM") + " " + Format(Now, " mmm d yyyy") + ".wav"
        'write the wave data out to disk. you can double click on the file to play it with sound recorder.
        Open filename For Binary Access Write As #1
        Put #1, , wavefile
        Close #1
    End If
    'hang up and wait for next call
End Sub

CraigLazarAuthor Commented:
Hi Jpconver

thanx for the input
i still not managed to get it working at the moment, i just gave the app to the client for now just so they had something to work with, i will take a look and see if you code will help

thanx allot again


Dear fdecker
I've rejected your proposed answer as Experts Exchange holds an experiment to work without the answer button.

See: <>
Paragraph: Site Update for Wednesday, November 06, 2002

By this rejection the Asker will be notified by mail and hopefully he will take his responsibility to finalize the question or post an additional comment.
The Asker sees a button beside every post which says "Accept This Comment As Answer" (including rejected answers) -- so if he/she thinks yours is the best, you'll be awarded the points and the grade.

EXPERTS: I will return in seven days to close this question.
Please leave your thoughts and recommendations here


Thanks !

Experts Exchange Moderator
Hi CraigLazar,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept jpconver's comment(s) as an answer.

CraigLazar, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer
CraigLazarAuthor Commented:
Hi Dan
Sorry fpr not getting back top this question
unfortunatley i was unable to get the app working the way i needed, please can u split the points to the people that tried to help me with this question


Split points.

Community Support Moderator @Experts Exchange

jpconver points for you at:

fdecker points for you at:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.