我需要语音合成的VB.NET的代码参考一下。
慧科服务 发布于2018-05 浏览:1914 回复:7
0
收藏
最近想研究一下语音合成技术。我用的是VB.NET   不知到那个网址是怎么在VB.NET里面传递给服务器     怎么从服务器上获取语音的。我需 要VB.NET完整代码用来参考。谢谢
收藏
点赞
0
个赞
共7条回复 最后由用户已被禁言回复于2022-04
#8慧科服务回复于2018-06

我要如何才能在VB.NET   里面把这个页面的语音下载到本地呢?

0
#7慧科服务回复于2018-06

我现在已经可以在浏览器里面用手动方式 合成任意语音了

0
#6慧科服务回复于2018-06

我现在 已经可以  换取token    并且  可以在浏览器里 用示例那个 代码获取 百度你好,这个语音了。

0
#5慧科服务回复于2018-06

我现在 在网上找到一段 C# 代码   我把他转成VB.NET

 

但是这段代码还是不会用。

Public Class BaiduTTSService
    Inherits IBaiduTTSService

    Public tok As String = GetBaiduToken()
    Private Const lan As String = "zh" '语言
    Private Const per As String = "4" '发音人选择 0位女  1位男  默认 女0为女声,1为男声,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女声
    Private Const ctp As String = "1" '客户端类型选择 web端为1  
    Private Const spd As String = "3" '范围0~9  默认 5   语速
    Private Const pit As String = "4" '范围0~9  默认 5   音调
    Private Const vol As String = "5" '范围0~9  默认 5   音量
    Private cuid As String = Computer.GetMacAddress() '机器Mak地址
    Private Const rest As String = "tex={0}&lan={1}&per={2}&ctp={3}&cuid={4}&tok={5}&spd={6}&pit={7}&vol={8}"

    '' 
    ''    tex 即:被转化的文本  可以是中英文结合体,如:hello 陈卧龙
    '' 
    '' 
    '' 

    Public Function GetBaiduUri(ByVal 被转化的文本 As String) As String
        Dim Uri As String = "http://tsn.baidu.com/text2audio?" & String.Format(rest, 被转化的文本, lan, per, ctp, cuid, tok, spd, pit, vol)
        Return Uri
    End Function
    ''
    ''获取百度Token  百度Token有效请为30天 
    '' 
    ''

    Public Shared Function GetBaiduToken() As String
        ''string Uri = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=你的client_id&client_secret=你的client_secret";
        ''string page = GetPage(Uri, "");
        ''string Token = GetJsonValue(page, "access_token");
        Return "24.926b57f9665a644fa7b38c76c021834d.2592000.1496304195.282335-9593280"
    End Function

    ''#region 获取网络资源

    ''
    ''获取网络资源  
    ''
    ''请求的URL
    ''发送的数据
    ''json格式的字符串

    Public Shared Function GetPage(ByVal 请求的URL As String, ByVal 发送的数据 As String) As String  'json格式的字符串
        ''WX_SendNews news = new WX_SendNews(); 
        ''posturl: news.Posturl;
        ''postData:news.PostData;

        Dim outstream As System.IO.Stream = Nothing
        Dim instream As System.IO.Stream = Nothing
        Dim sr As System.IO.StreamReader = Nothing
        Dim response As System.Net.HttpWebResponse = Nothing
        Dim request As System.Net.HttpWebRequest = Nothing
        Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
        Dim data As Byte() = encoding.GetBytes(发送的数据)
        ''准备请求...  
        Try
            ''设置参数 
            request = TryCast(System.Net.WebRequest.Create(请求的URL), System.Net.HttpWebRequest)
            Dim cookieContainer As System.Net.CookieContainer = New System.Net.CookieContainer()
            request.CookieContainer = cookieContainer
            request.AllowAutoRedirect = True
            request.Method = "POST"
            request.ContentType = "application/x-www-form-urlencoded"
            request.ContentLength = data.Length
            outstream = request.GetRequestStream()
            outstream.Write(data, 0, data.Length)
            outstream.Close()
            ''发送请求并获取相应回应数据  
            response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
            ''直到request.GetResponse()程序才开始向目标网页发送Post请求
            instream = response.GetResponseStream()
            sr = New System.IO.StreamReader(instream, encoding)
            ''返回结果网页(html)代码 
            Dim content As String = sr.ReadToEnd()
            Dim err As String = String.Empty
            Return content
        Catch ex As Exception
            Dim err As String = ex.Message
            Return String.Empty
        End Try
    End Function
    ''#region 获取Json字符串某节点的值
    ''
    '' 获取Json字符串某节点的值
    ''

    Public Shared Function GetJsonValue(ByVal jsonStr As String, ByVal key As String) As String
        Dim result As String = String.Empty

        If Not String.IsNullOrEmpty(jsonStr) Then
            key = """" & key.Trim(""""c) & """"
            Dim index As Integer = jsonStr.IndexOf(key) + key.Length + 1

            If index > key.Length + 1 Then
                ''先截逗号,若是最后一个,截“}”号,取最小值
                Dim [end] As Integer = jsonStr.IndexOf(","c, index)

                If [end] = -1 Then
                    [end] = jsonStr.IndexOf("}"c, index)
                End If

                result = jsonStr.Substring(index, [end] - index)
                result = result.Trim(New Char() {""""c, " "c, "'"c}) '过滤引号或空格
            End If
        End If

        Return result
    End Function
End Class
0
#4慧科服务回复于2018-05

我知到那个 接口,也知到那是个网址,但如何在VB中使用,需要替换那些东西?

我在网上也找到下面的代码,但不知到那个变量替换那里。


Imports System.IO
Imports System.Net

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim appKey As String = "u5qjime0wVYtEiCPvYB0Srrt"
        Dim appSecret As String = "toEWlbx0CuIe2nx2QbwB5Xs3WyR4sbMK"

        'https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=Va5yQRHl********LT0vuXV4&client_secret=0rDSjzQ20XUj5i********PQSzr5pVw2


    End Sub

    Public Shared Function 获取数据(ByVal url As String, ByVal data As String) As String

        Dim 请求 As HttpWebRequest = WebRequest.Create(url + "?" + data)
        请求.Method = "GET" '获取或设置请求的方法。
        Dim 流读取器 As StreamReader = New StreamReader(请求.GetResponse().GetResponseStream)
        Return 流读取器.ReadToEnd

    End Function

    Public Shared Function 发送数据(ByVal url As String, ByVal data As String) As String

        ServicePointManager.Expect100Continue = False
        Dim 请求 As HttpWebRequest = WebRequest.Create(url)
        '//Post请求方式  
        请求.Method = "POST" ' '获取或设置请求的方法。

        '内容类型  
        请求.ContentType = "application/x-www-form-urlencoded"
        '将URL编码后的字符串转化为字节  
        Dim 编码 As New System.Text.UTF8Encoding()
        Dim 字节流 As Byte() = 编码.GetBytes(data)
        '设置请求的 ContentLength   
        请求.ContentLength = 字节流.Length
        '获得请 求流  
        Dim 新流 As Stream = 请求.GetRequestStream()
        新流.Write(字节流, 0, 字节流.Length)
        新流.Close()
        '获得响应流  
        Dim sr As StreamReader = New StreamReader(请求.GetResponse().GetResponseStream)
        Return sr.ReadToEnd
    End Function
End Class
0
#3fujiayi1984回复于2018-05

http://speech.baidu.com/docs/tts/134

0
#2慧科服务回复于2018-05

继续等待援兵

0
TOP
切换版块