首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在vb.net中使用google cloud speech API将音频文件转录为文本文件

问在vb.net中使用google cloud speech API将音频文件转录为文本文件
EN

Stack Overflow用户
提问于 2018-07-24 03:22:10
回答 1查看 470关注 0票数 0

我找不到Google Cloud speech API来使用vb.net将.wav文件转录成.txt文件。

身份验证正在工作:

代码语言:javascript
复制
AuthExplicit2("AudioTranscription", "C:\AudioTranscription\GoogleAuthentication\GoogleTranscriptionAuthentication.json")

我试过寻找代码示例作为模板,但我就是搞不懂代码。有人能帮我吗?

代码语言:javascript
复制
    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
EN

回答 1

Stack Overflow用户

发布于 2018-08-02 03:30:37

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51485865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档