none
Text to Speech Code error RRS feed

  • Question

  • Code I'm trying to use is located at:  https://msdn.microsoft.com/en-us/library/ms717065(v=vs.85).aspx

    Specific section on this page:  Speak to a wav file in automation

    Software Using:  Visual Studio VB.NET

    O/S:  Win10

    Issue:  When I try to use the code I get the following error:

    Severity Code Description Project File Line Suppression State
    Error BC30451 'SSFMCreateForWrite' is not declared. It may be inaccessible due to its protection level. Weather v1 \\DC-INK-SHARE\share\WXYZ Weather\Weather\Weather v1\Weather v1\Weather1.vb 142 Active

    Line 142 code is:   FileStream.Open(Filename, SSFMCreateForWrite, True)    Using it this way I can not compile program.

    I have the following in my code:

    Imports System.IO
    Imports System
    Imports System.Text
    Imports SpeechLib

    Rest of code:

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim Filename As String
            Dim FileStream As New SpFileStream
            Dim Voice As New SpVoice
            'Create a SAPI Voice
            Voice = New SpVoice
            'The output audio data will be saved to ttstemp.wav file
            filename = ("c:\ttstemp.wav")
            ' Create a file; set DoEvents=True so TTS events will be saved to the file
            FileStream.Open(Filename, SSFMCreateForWrite, True)
            'Set the output to the FileStream
            Voice.AudioOutputStream = filestream
            'Speak the Text
            Voice.Speak("Hello World!")
            'Close the stream
            filestream.Close()
            'Release the objects
            filestream = Nothing
            Voice = Nothing

        End Sub

    I've tried:  FileStream.Open(Filename, SpeechStreamFileMode.SSFMCreateForWrite, True)  When using this the program will compile, but I get this error:

    System.ArgumentException: 'Value does not fall within the expected range.'

    Hope you can help

    Derek Cosby

    drcoz@aol.com


    Derek Cosby Virginia

    Saturday, September 16, 2017 10:54 PM

Answers

  • Hi drcoz,

    I can reproduce your issue if I save .wav file in the c the root directory of the disk, and if I change the saved address, it works fine.

    If the filename is : Filename = "C:\test.wav", you will get this issue,

    If the file is not in C the root directory of the disk or other disk, you will get no error message like this:

     Filename = "C:\Test\test.wav" or  Filename = "D:\test\test.wav", you can try it.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by drcoz Tuesday, September 19, 2017 1:48 PM
    Tuesday, September 19, 2017 1:35 AM
    Moderator

All replies

  • Hi Derek Cosby,

    Welcome to the MSDN forum.

    Refer to your description, your issue is about VB development. Since our forum is to discuss the VS IDE, I will help you move this thread to the VB development forum to seek for a more professional support, thank you for your understanding.

    Best regards,

    Sara


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, September 18, 2017 2:59 AM
  • Hi drcoz,

    I have tried your code and I don't get any error message, it works fine and save a .wav file. May be caused by this small problem : I don't see you assign a value to FileName, then you use FileStream.Open(Filename, SSFMCreateForWrite, True), I think you can modify you code and try it again.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 18, 2017 7:06 AM
    Moderator
  • Cherry,

    I do have filename assigned a value:   filename = ("c:\ttstemp.wav")

    I just created a new project and put this code into it by itself, I still get the same error.  I tested this to see if the bigger code I'm using was causing the issue, but still have the issue.

    Does it make any difference that I'm using MS Visual Studio Community 2017?

    I did your recommendations and still not working.  I do have IMPORTS SpeechLib in the code as well, any other references I may need?

    My code won't compile with: FileStream.Open(Filename, SSFMCreateForWrite, True)

    I have to use:  FileStream.Open(Filename, SpeechStreamFileMode.SSFMCreateForWrite, True) to get it to compile.

    But even with that still get both errors I described in my original message.


    Derek Cosby Virginia

    Monday, September 18, 2017 10:02 PM
  •  In VB.Net you can just add a reference to (System.Speech) and use the SpeechSynthesizer Class to do this.  For example...

    'On the menu, open the (Project) dropdown and select (Add Reference). In the Reference Manager window, select the (Assemblies) or (.Net) tab.
    ' There you can scroll down and check the checkbox in front of (System.Speech). Then press the (Ok) button.
    Imports System.Speech.Synthesis
    
    Public Class Form1
        Private WithEvents SpchSynth As New SpeechSynthesizer()
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            SpchSynth.SetOutputToWaveFile("C:\TestFolder\TextToAudio.wav")
            SpchSynth.SpeakAsync("Read this text into my wave audio file.")
        End Sub
    
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            SpchSynth.Dispose()
        End Sub
    
        Private Sub SpchSynth_SpeakCompleted(sender As Object, e As SpeakCompletedEventArgs) Handles SpchSynth.SpeakCompleted
            MessageBox.Show("Done reading the text to the audio file.")
        End Sub
    End Class
     

     There are several methods to choose from to read the text into a wave audio file.  Some read to a stream,  some directly to a wave file,  even one to append the text to a stream.  You can refer to the SetOutput.... methods of the SpeechSynthesizer Class.


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Tuesday, September 19, 2017 12:41 AM
    Tuesday, September 19, 2017 12:33 AM
  • Hi drcoz,

    I can reproduce your issue if I save .wav file in the c the root directory of the disk, and if I change the saved address, it works fine.

    If the filename is : Filename = "C:\test.wav", you will get this issue,

    If the file is not in C the root directory of the disk or other disk, you will get no error message like this:

     Filename = "C:\Test\test.wav" or  Filename = "D:\test\test.wav", you can try it.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by drcoz Tuesday, September 19, 2017 1:48 PM
    Tuesday, September 19, 2017 1:35 AM
    Moderator
  • That worked...wow something so simple as putting it in another directory can drive a programmer nuts.  :)

    Cherry, your awesome!!!!   Thanks!!!


    Derek Cosby Virginia

    Tuesday, September 19, 2017 1:49 PM
  • IronRazerz

    Thanks!  I'll keep your suggestion in mind.  Cherry solved my problem.


    Derek Cosby Virginia

    Tuesday, September 19, 2017 1:50 PM
  • That worked...wow something so simple as putting it in another directory can drive a programmer nuts.

     I would imagine that the error has something to do with the C: drive being a protected directory like the Windows and Programs directories are.  If your app does not have the correct permissions,  it will not have "Write" access to these directories but,  you will have rights to "Read" a file from them.  It has been this way since Windows Vista.  It is part of the UAC security to stop malicious software from freely accessing vital directories.

    If you say it can`t be done then i`ll try it

    Tuesday, September 19, 2017 4:21 PM