csharp:Google TTS API text to speech

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

using
System;

using
System.Collections.Generic;

using
System.ComponentModel;

using
System.Data;

using
System.Drawing;

using
System.Linq;

using
System.Text;

using
System.Windows.Forms;

using
System.IO;

using
System.Net;

using
System.Threading;

using
NAudio.Wave;//http://naudio.codeplex.com/

using
NAudio.CoreAudioApi;

using
System.Web;

using
System.Media;

using
SpeechLib;//NET2.0 引用 Speech sdk 5.1 在COM选项卡里面的Microsoft Speech  object  library引用 已经有11.0版本

using
Microsoft.DirectX;

using
Microsoft.DirectX.DirectSound;

namespace
Speech

{

    /// <summary>

    /// Csharp: Google TTS API 文本语音读取

    ///  涂聚文

    /// </summary>

    public
partial class Form2 : Form

    {

        /// <summary>

        ///

        /// </summary>

        /// <param name="FileName"></param>

        public
void PlaySound(string
FileName)

        {

            //要加载COM组件:Microsoft speech object Library

            if
(!System.IO.File.Exists(FileName))

            {

                return;

            }

            SpeechLib.SpVoiceClass pp = new
SpeechLib.SpVoiceClass();

            SpeechLib.SpFileStreamClass spFs = new
SpeechLib.SpFileStreamClass();

            spFs.Open(FileName, SpeechLib.SpeechStreamFileMode.SSFMOpenForRead, true);

            SpeechLib.ISpeechBaseStream Istream = spFs as
SpeechLib.ISpeechBaseStream;

            pp.SpeakStream(Istream, SpeechLib.SpeechVoiceSpeakFlags.SVSFIsFilename);

            spFs.Close();

        }

        /// <summary>

        ///

        /// </summary>

        public
Form2()

        {

            InitializeComponent();

        }

        /// <summary>

        ///

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private
void Form2_Load(object
sender, EventArgs e)

        {

            this.textBox1.Text = "中华人民共和国";

            //ok

            WebClient web = new
WebClient();

            web.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 9.0; Windows;)");

            string
encstr = string.Empty;

            string
filename = "tts.mp3"; //could also be tts.wav

            string
s = "中华人民共和国涂聚文投诉";

            encstr = Uri.EscapeDataString(s);

            Console.WriteLine(encstr);

            web.DownloadFile("http://translate.google.com/translate_tts?ie=UTF-8&tl=zh-cn&q="
+ encstr, ".\\"
+ filename);

            //PlaySound(Application.StartupPath+"\\"+filename);

            //SoundPlayer sp = new SoundPlayer();

            //sp.SoundLocation = Application.StartupPath + "\\" + filename;

            //sp.LoadAsync();

            //sp.PlaySync();

            //sp.PlayLooping();

            //Device dv = new Device();

            //SecondaryBuffer buf = new SecondaryBuffer(Application.StartupPath + "\\" + filename, dv);

            //buf.Play(0, BufferPlayFlags.Looping);

            this.axWindowsMediaPlayer1.URL = Application.StartupPath + "\\"
+ filename;

        }

        bool
waiting = false;

        AutoResetEvent stop = new
AutoResetEvent(false);

        /// <summary>

        /// 英文可以,中文不行

        /// </summary>

        /// <param name="url"></param>

        public
void PlayMp3FromUrl(string
url)

        {

            try

            {

                url = HttpUtility.UrlDecode(url);

                using
(Stream ms = new
MemoryStream())

                {

                    using
(Stream stream = WebRequest.Create(url).GetResponse().GetResponseStream())//HttpUtility.UrlDecode(

                    {

                        //UTF8Encoding encoding = new UTF8Encoding();

                        //byte[] buffer = encoding.GetBytes(url);

                        //stream.Write(buffer, 0, buffer.Length);

                        //stream.Close();

                        byte[] buffer = new
byte[32768];//32768

                        int
read;

                        while
((read = stream.Read(buffer, 0, buffer.Length)) > 0)

                        {

                            ms.Write(buffer, 0, read);

                        }

                        //using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))

                        //{

                        //    writer.Write(url);

                        //}

                    }

                    //using (Stream stream = request.GetRequestStream())

                    //using (StreamWriter writer = new StreamWriter(requestStream, Encoding.UTF8))

                    //{

                    //    writer.Write(url);

                    //}

                    ms.Position = 0;

                    using
(WaveStream blockAlignedStream =

                        new
BlockAlignReductionStream(

                            WaveFormatConversionStream.CreatePcmStream(

                                new
Mp3FileReader(ms))))

                    {

                        using
(WaveOut waveOut = new
WaveOut(WaveCallbackInfo.FunctionCallback()))

                        {

                            waveOut.Init(blockAlignedStream);

                            waveOut.PlaybackStopped += (sender, e) =>

                            {

                                waveOut.Stop();

                            };

                            waveOut.Play();

                            waiting = true;

                            stop.WaitOne(10000);

                            waiting = false;

                        }

                    }

                }

            }

            catch
(Exception ex)

            {

                ex.Message.ToString();

            }

        }

        /// <summary>

        /// http://translate.google.com/translate_tts?tl=zh-cn&q=%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD

        /// http://translate.google.cn/translate_tts?ie=UTF-8&q=%E4%B8%AD%E5%9B%BD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD&tl=zh-cn&prev=input

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private
void button1_Click(object
sender, EventArgs e)

        {

            

            

            //var playThread = new Thread(() => PlayMp3FromUrl("http://translate.google.com/translate_tts?tl=en&q=" + HttpUtility.UrlEncode(this.textBox1.Text)));

            string
str = HttpUtility.UrlEncode(this.textBox1.Text);

            var
playThread = new
Thread(() => PlayMp3FromUrl("http://translate.google.com/translate_tts?ie=UTF-8&tl=zh-cn&q="
+ str));// HttpUtility.UrlEncode(

            playThread.IsBackground = true;

            playThread.Start();

        }

    }

}

csharp:Google TTS API text to speech,布布扣,bubuko.com

时间: 2024-08-02 02:48:03

csharp:Google TTS API text to speech的相关文章

开源TTS(Text To Speah)的选择和使用

TTS是Text To Speech的缩写,即"从文本到语音",是人机对话的一部分,让机器能够说话. TTS是语音合成应用的一种,它将文件内容或应用上的文字等,如应用菜单或者网页,转换成自然语音输出. TTS不仅能帮助有视觉障碍的人阅读计算机上的信息,更能增加文本文档的可读性. 一.比较流行的开源TTS项目 以下信息来自:TTS open source project MARY-- Text-to-Speech System MARY is an open-source, multil

重新想象 Windows 8.1 Store Apps (87) - TTS: Speak Text, Speak SSML

[源码下载] 作者:webabcd 介绍重新想象 Windows 8.1 Store Apps 之 TTS(Text To Speech) Speak Text Speak SSML 示例1.演示如何通过 TTS 朗读一段文本,以及如何将其保存为音频文件SpeakText.xaml <Page x:Class="Windows81.TTS.SpeakText" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/pre

Csharp: speech to text, text to speech in win

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

通过google cloud API 使用 WaveNet

Cloud Text-to-Speech 中使用了WaveNet,用于TTS,页面上有Demo.目前是BETA版 使用方法 注册及认证参考:Quickstart: Text-to-Speech 安装google clould 的python库 安装 Google Cloud Text-to-Speech API Python 依赖(Dependencies),参见github说明 ----其中包括了,安装pip install google-cloud-texttospeech==0.1.0 为

如何将经纬度利用Google Map API显示C# VS2005 Sample Code

原文 如何将经纬度利用Google Map API显示C# VS2005 Sample Code 日前写了一篇如何用GPS抓取目前所在,并回传至资料库储存,这篇将会利用这些回报的资料,将它显示在地图上,这个做法有两种,最简单的就是直接传值到Google Maps上. 举例来说,当我们知道经纬度后,只要将数据套到以下网址即可. http://maps.google.com/maps?q=25.048346%2c121.516396 在参数q=后面,就可以加上经纬度了. 25.048346是Lati

Google Maps API Web Services

原文:Google Maps API Web Services 摘自:https://developers.google.com/maps/documentation/webservices/ Google Maps API Web Services 本文将探讨 Google Maps API Web Services,这是一个为您的地图应用程序提供地理数据的 Google 服务的 HTTP 接口集合.本指南仅旨在介绍通用于所有不同服务的 Web 服务和托管信息.每个服务的单个文档位于以下位置:

google map api v3

<!DOCTYPE html> <html> <head> <script type="text/javascript"> function killerrors() { return true; } window.onerror = killerrors; </script> <meta name="viewport" content="initial-scale=1.0, user-sc

在云平台上基于Go语言+Google图表API提供二维码生成应用

二维码能够说已经深深的融入了我们的生活其中.到处可见它的身影:但通常我们都是去扫二维码, 曾经我们分享给朋友一个网址直接把Url发过去,如今我们能够把自己的信息生成二维码再分享给他人. 这里就分享一下基于Go语言+Google图表API提供二维码生成功能的小应用,并演示怎样把它公布到云平台上, 让每一个人都能够通过网络訪问使用它. Google图表API Google在http://chart.apis.google.com 上提供了一个将表单数据自己主动转换为图表的服务. 只是,该服务非常难交

容易使用的读取文本播放器 Text to Speech Maker 2.5

FilmConvert Stand Alone 1.216 MacOSXAutodesk.Smoke.v2015.SP1.MacOSX 1DVDAutodesk Smoke 2015提供更快的效能和更平易近人的价格专 为以Mac计算机作业的小型工作室设计,Smoke 2015专业影音特效和剪辑工具现在具备了 3D追踪.新的Timeline FX工作流程.针对搭载OS X Mavericks操作系统的新版Mac Pro新增硬件支持和系统运作的最佳化,并与Final Cut Pro X提供更佳的互通