【问题标题】:Transcribe Audio file to text file using google cloud speech API in vb.net使用 vb.net 中的谷歌云语音 API 将音频文件转录为文本文件
【发布时间】:2018-07-23 19:22:10
【问题描述】:

我无法弄清楚使用 vb.net 将 .wav 文件转录为 .txt 文件的 Google Cloud 语音 API。

身份验证有效:

AuthExplicit2("AudioTranscription", "C:\AudioTranscription\GoogleAuthentication\GoogleTranscriptionAuthentication.json")

我已尝试查找代码示例以用作模板,但我就是无法弄清楚代码。 谁能帮我解决这个问题?

    Try
        Dim fileStream As FileStream = File.OpenRead("C:\AudioTranscription\Audio\dictation-partial.flac")
        'Dim memoryStream As MemoryStream = File.OpenWrite("C:\AudioTranscription\Audio\dictation-partial.flac")
        'Dim memoryStream As MemoryStream = New MemoryStream("C:\AudioTranscription\Audio\dictation-partial.txt")
        memoryStream.SetLength(fileStream.Length)
        fileStream.Read(memoryStream.GetBuffer(), 0, CInt(fileStream.Length))
        Dim BA_AudioFile As Byte() = memoryStream.GetBuffer()
        Dim _HWR_SpeechToText As HttpWebRequest = Nothing
        '_HWR_SpeechToText = CType(HttpWebRequest.Create("https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=YOUR_API_KEY_HERE"), HttpWebRequest)
        _HWR_SpeechToText.Credentials = CredentialCache.DefaultCredentials
        _HWR_SpeechToText.Method = "POST"
        _HWR_SpeechToText.ContentType = "audio/x-flac; rate=44100"
        _HWR_SpeechToText.ContentLength = BA_AudioFile.Length
        Dim stream As Stream = _HWR_SpeechToText.GetRequestStream()
        stream.Write(BA_AudioFile, 0, BA_AudioFile.Length)
        stream.Close()
        Dim HWR_Response As HttpWebResponse = CType(_HWR_SpeechToText.GetResponse(), HttpWebResponse)

        If HWR_Response.StatusCode = HttpStatusCode.OK Then
            Dim SR_Response As StreamReader = New StreamReader(HWR_Response.GetResponseStream())
            Console.WriteLine(SR_Response.ReadToEnd())
        End If
    Catch ex As Exception
        Console.WriteLine(ex.ToString())
    End Try

    Console.ReadLine()
    imgAudioFile.Visible = True

【问题讨论】:

    标签: vb.net speech-recognition speech-to-text google-cloud-speech


    【解决方案1】:

    public documentation 中的代码需要client libraries 或创建post request。 当您使用发布请求时,您应该将音频文件上传到Cloud Storage,以便根据文档使用请求中的 url,而不是使用本地文件。 关于您的 POST 请求,您可以根据 this post 在您的 post 请求中发送 JSON body

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多