Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7529407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:39:14+00:00 2026-05-30T04:39:14+00:00

I am trying to make a voice recognition thing with google’s voice api. I

  • 0

I am trying to make a voice recognition thing with google’s voice api.

I modified UPLOADFILEEX function that can be found on codeproject…

The file I wish to delete is C:\record.flac

Here is the function below

         Public Shared Function UploadFile(ByVal uploadfilename As String, ByVal url As String, ByVal fileFormName As String, ByVal contenttype As String, ByVal querystring As System.Collections.Specialized.NameValueCollection, ByVal cookies As CookieContainer) As String
    If (fileFormName Is Nothing) OrElse (fileFormName.Length = 0) Then
        fileFormName = "file"
    End If
    If (contenttype Is Nothing) OrElse (contenttype.Length = 0) Then
        contenttype = "application/octet-stream"
    End If
    Dim postdata As String
    postdata = "?"
    If Not (querystring Is Nothing) Then
        For Each key As String In querystring.Keys
            postdata += key + "=" + querystring.Get(key) + "&"
        Next
    End If
    Dim uri As Uri = New Uri(url + postdata)
    Dim boundary As String = "----------" + DateTime.Now.Ticks.ToString("x")
    Dim webrequest As HttpWebRequest = CType(Net.WebRequest.Create(uri), HttpWebRequest)
    webrequest.CookieContainer = cookies
    webrequest.ContentType = "audio/x-flac; rate=16000"
    webrequest.Method = "POST"
    Dim sb As StringBuilder = New StringBuilder
    sb.Append("--")
    sb.Append(boundary)
    sb.Append("" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "")
    sb.Append("Content-Disposition: form-data; name=""")
    sb.Append(fileFormName)
    sb.Append("""; filename=""")
    sb.Append(IO.Path.GetFileName(uploadfilename))
    sb.Append("""")
    sb.Append("" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "")
    sb.Append("Content-Type: ")
    sb.Append(contenttype)
    sb.Append("" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "")
    sb.Append("" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "")
    Dim postHeader As String = sb.ToString
    Dim postHeaderBytes As Byte() = Encoding.UTF8.GetBytes(postHeader)
    Dim boundaryBytes As Byte() = Encoding.ASCII.GetBytes("" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "--" + boundary + "" & Microsoft.VisualBasic.Chr(13) & "" & Microsoft.VisualBasic.Chr(10) & "")
    Dim fileStreama As FileStream = New FileStream(uploadfilename, FileMode.Open, FileAccess.Read)
    Dim length As Long = postHeaderBytes.Length + fileStreama.Length + boundaryBytes.Length
    webrequest.ContentLength = length
    Dim requestStream As Stream = webrequest.GetRequestStream
    requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length)
    Dim sendBuffer(Math.Min(4096, fileStreama.Length)) As Byte
    Dim bytesRead As Integer = 0
    Do
        bytesRead = fileStreama.Read(sendBuffer, 0, sendBuffer.Length)
        If bytesRead = 0 Then Exit Do
        requestStream.Write(sendBuffer, 0, bytesRead)
    Loop
    requestStream.Write(boundaryBytes, 0, boundaryBytes.Length)
    Dim responce As WebResponse = webrequest.GetResponse
    Dim s As Stream = responce.GetResponseStream
    Dim sr As StreamReader = New StreamReader(s)
    Return sr.ReadToEnd
    sr.Dispose()
    s.Dispose()
    fileStreama.Dispose()
    requestStream.Dispose()
    webrequest.Abort()
    responce.Close()

End Function

The function WORKS (Thankgod) but whenever I want to clear up (i.e. delete the audio file that is located in the c:) it just hangs and nothing happens…

Below is my code that executes on the formclosing event….

      Private Sub Form1_Close(sender As System.Object, e As System.EventArgs) Handles MyBase.FormClosing
    Dim di As New IO.DirectoryInfo("c:\")
    Dim diar1 As IO.FileInfo() = di.GetFiles()
    Dim dra As IO.FileInfo
    For Each dra In diar1
        If dra.Name.Contains("record.") Then
            dra.Delete()
        End If
    Next
End Sub

As you probably may be able to see from the function I HAVE TRIED TO REMOVE ALL THE STREAMS AND CLOSE THEM SO THE FILE IS NOT BEING ACCESSED

BUT it still hangs and when I try manually delete it… it tells me it is being used by another process (which is my program) – (I use ffmpeg to convert the .wav to .flac file but that does not cause any problems)….

What am I doing wrong…

Have I missed the closing of some stream or something.

By the way the uploadfilename string is c:\record.flac (just for your information – I dont think it will help)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:39:16+00:00Added an answer on May 30, 2026 at 4:39 am

    Your function is calling Return BEFORE disposing of the file stream. This means that your Dispose call is never fired.. and the stream holds onto a file reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make use of a java api for google voice (available here:
Trying to make a make generic select control that I can dynamically add elements
I am trying to make a prog which can record voice and store it
Trying to make a custom :confirm message for a rails form that returns data
trying to make a page which will recursively call a function until a limit
I'm trying to make a listview from an arraylist using the tutorial i found
trying to make 5 curl childs for curl handler and defining them, but can't
I have some code that I am trying to make it play nicely with
I'm trying to make a simple app that will ping a uri and tell
I am trying make long screen to vertical direction. So, I need a screen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.