Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I use MS TTS - text to speech to read a field in a database and then save it as a wav file?

Posted on 2007-08-09
8
Medium Priority
?
285 Views
Last Modified: 2013-11-05
How do I use MS's (TTS) text to speech function-to read a record from a db and save it as a wav file? Example: Table speech1 in Speech.mdb has 2 fields; FileName & ReadText. I need to have TTS read the
entry in the field ReadText and save it as the entry in FileName as a wav
file.
0
Comment
Question by:rcwherrera
  • 4
  • 4
8 Comments
 
LVL 14

Expert Comment

by:Matti
ID: 19668575
Hi!

There is a sample program:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=50959&lngWId=1#zip

Make modification and adopt parts of code so you can have the TTS part and the save to wave part from it.

It uses Microsoft Speech Object Library this is from Speech SDK 5.1

Do you need sample code for reading the database too?

Matti
0
 

Author Comment

by:rcwherrera
ID: 19671769
Thank you for the quick response!  Very much appreciated.
Yes, need the code for reading the database.  Can all of this be done in access itself? I would like to use the vb in the db to do this as I don't have VB itself and the more code that is available the better.
0
 
LVL 14

Expert Comment

by:Matti
ID: 19672347
Hi!

There is nothing VB only so I quess it cold be done in Access too, now it's in VB.

Here is modifications to that PSC project it now use database. it will loop the whole database.

Matti

This is the test database contents in my test:
FileName      ReadText
c:\test1.wav      This is test
c:\test2.wav      This is second test

Add reference Microsoft DAO 3.6 Object Library

New module:
Public DB As Database, rs As Recordset

Public Sub OpenDB()
Set DB = OpenDatabase(App.Path + "\Speech.mdb", True, True)
Set rs = DB.OpenRecordset("speech1")
End Sub

Public Sub CloseDB()
rs.Close
DB.Close
Set rs = Nothing
Set DB = Nothing
End Sub

Command button on frmTTS, this is the start control:

Private Sub Command1_Click()
Dim i&
OpenDB
    On Error GoTo ErrHandler
    rs.MoveFirst
    For i = 1 To rs.RecordCount
    If m_bPaused Then Voice.Resume
    DoEvents
    saveToWaveFile rs.Fields("FileName"), rs.Fields("ReadText")
    DoEvents
    rs.MoveNext
    Next i
    CloseDB
    Exit Sub
   
ErrHandler:
    AddDebugInfo "Speak Error: ", Err.Description
    SetSpeakingState False, m_bPaused
End Sub


Replacemet for sub saveToWaveFile:

Private Sub saveToWaveFile(s As String, Stext As String)
    On Error GoTo ErrHandler
   
    ' create a wave stream
    Dim cpFileStream As New SpFileStream
   
    ' Set output format to selected format
    cpFileStream.Format.Type = FormatCB.ItemData(FormatCB.ListIndex)
   
    ' Open the file for write
   
    cpFileStream.Open s, SSFMCreateForWrite, False
   
    ' Set output stream to the file stream
    Voice.AllowAudioOutputFormatChangesOnNextSet = False
    Set Voice.AudioOutputStream = cpFileStream
   
    ' show action
    AddDebugInfo "Save to .wav file"
   
    ' speak the given text with given flags
    Voice.Speak Stext, m_speakFlags
   
    ' wait until it's done speaking with a really really long timeout.
    ' the tiemout value is in unit of millisecond. -1 means forever.
    Voice.WaitUntilDone -1
   
    ' Since the output stream was set to the file stream, we need to
    ' set back to the selected audio output by calling AudioOutputCB_Click
    ' as if user just changed it through UI
    AudioOutputCB_Click
   
    ' close the file stream
    cpFileStream.Close
    Set cpFileStream = Nothing
   
    Exit Sub

ErrHandler:
    'User pressed the Cancel button, do not show error
    If Not (Err.Number = 32755) Then
        AddDebugInfo "Save to Wave file Error: ", Err.Description
    End If
   
    If Not cpFileStream Is Nothing Then
        Set cpFileStream = Nothing
    End If
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rcwherrera
ID: 19672872
Wow, thank you.  I downloaded the zip file from the attached URL, but how do I open /add the contents to Access/VB, I see a bunch of files but not sure on how to open them. Not sure how to 'connect' them to a db.

I added a new module and frmTTS to the db and added the command button and added the code you provided, where do I add the code beneath "Replacemet for sub saveToWaveFile:" ?  I am also getting a compile error that AddDebugInfo is a sub or function not defined.  I apologize for all the questions, but the more I think I know about vb, the less I really know, if that makes any sense.  
0
 

Author Comment

by:rcwherrera
ID: 19672957
I was able to import the .bas files but not the .frm, i get an error that they are not supported in VBE.
0
 
LVL 14

Accepted Solution

by:
Matti earned 2000 total points
ID: 19673020
Hi!

Well I tested it here and I think I gave all modifications. It could be the path when you save a wave file
Change the call if you don't have path in the database:
saveToWaveFile app.path & "\" + rs.Fields("FileName") & ".wav" , rs.Fields("ReadText")

"Replacemet for sub saveToWaveFile:"
There is a sub in frmTTS "saveToWaveFile", replace this whit the new version I gave you. I think you now added it to module, it's private so it need to be in frmTTS code.

Note that there are existing call to that sub in the code these will rise compile errors as there are now variables in the call. remove these error causing calls you don't need these to get it working.

Matti
0
 

Author Comment

by:rcwherrera
ID: 19673076
I am sure all of this is correct, but it is too advanced for me, at this point.  Thank you for all the assistance.
0
 
LVL 14

Expert Comment

by:Matti
ID: 19673125
Hi!

This is hopeles whitout file, here it is:

http://62.142.251.150/sample/test.zip

Matti
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question