如何听到文本到语音翻译的音频 [英] How to hear the audio of a text to speech translation

查看:159
本文介绍了如何听到文本到语音翻译的音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想听到的声音,当我点击的图像(如音频图像)上。通过谷歌翻译得到一个句子的声音文件。我想做到这一点没有得到重新定向到不同的页面。我应该怎么办呢?我尝试使用HTML5音频标签,但没成功无论是。

 < HTML和GT;
<身体GT;
< A HREF =htt​​p://translate.google.com/translate_tts?q=My+name+is+John>我的名字是约翰< / A>< /身体GT;
< / HTML>


解决方案

EDIT2

下面的<一个href=\"http://stackoverflow.com/questions/187098/cross-platform-cross-browser-way-to-play-sound-from-javascript\">another解决方案也张贴上,这样可以帮助你。


修改

一个更强大的解决方案。经测试,在IE8和Firefox

 &LT; HTML和GT;
  &LT; HEAD&GT;
    &LT;脚本类型=文/ JavaScript的SRC =htt​​p://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&GT;&LT; / SCRIPT&GT;
  &LT; /头&GT;
  &LT;身体GT;
    &所述; IMG SRC =htt​​p://www.blackwellokradio.com/click-me.jpg的onclick =$ .sound.play('http://translate.google.com/translate_tts?q=My+name+为+约翰')的风格=光标:手;光标:指针; /&GT;
  &LT; /身体GT;
&LT; / HTML&GT;
&LT;! - 在理想情况下,你会把这一个单独的文件。 SRC:http://dev.jquery.com/browser/trunk/plugins/sound/jquery.sound.js?rev=5750-->
&LT;脚本类型=文/ JavaScript的&GT;
/ **
 * jQuery的声音插件(不闪光)
 *
 * script.aculo.ussound.js港(http://script.aculo.us),根据儒勒Gravinese code(http://www.webveteran.com/)
 *
 *版权所有(C)2007JörnZaefferer(http://bassistance.de)
 *
 *根据MIT许可证:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * $ $标识
 * // **
 * API文档
 *
 * //从URL播放声音
 * $ .sound.play(URL)
 *
 * //从URL播放声音,在轨道上,停止任何声音已经是轨道上运行
 * $ .sound.play(URL,{
 *曲目:TRACK1
 *});
 *
 * //增加超时到四秒从DOM删除声音对象更长的声音之前
 * $ .sound.play(URL,{
 *超时:4000
 *});
 *
 * //通过去除戏返回元素停止声音
 *变种声音= $ .sound.play(URL);
 * sound.remove();
 *
 * //禁止播放声音
 * $ .sound.enabled = FALSE;
 *
 * //让播放声音
 * $ .sound.enabled = TRUE
 * /(函数($){$ .sound = {
    曲目:{},
    启用:真实,
    模板:功能(SRC){
        回归'&LT;嵌入风格=高度:0循环=假SRC =+ SRC +'自动启动=真隐藏=真/&GT;';
    },
    玩:功能(URL,期权){
        如果(!this.enabled)
            返回;
        VAR设置= $ .extend({
            网址:网址,
            超时:2000
        },期权);        如果(settings.track){
            如果(this.tracks [settings.track]){
                VAR电流= this.tracks [settings.track]
                // TODO检查时,停止缴费是,肯定不是一个jQuery对象
                current.Stop&功放;&安培; current.Stop();
                current.remove();
            }
        }        VAR元= $ .browser.msie
            ? $('&LT; BGSOUND /&GT;')。ATTR({
                SRC:settings.url,
                循环:1,
                自动启动:真
              })
            :$(this.template(settings.url));        element.appendTo(身体);        如果(settings.track){
            this.tracks [settings.track] =元素;
        }        如果(选项){
            的setTimeout(函数(){
                element.remove();
            },options.timeout)
        }        归元;
    }
};})(jQuery的);
&LT; / SCRIPT&GT;


下面是一个方法嵌入的QuickTime。你可以很容易地使用Windows Media Player ...

 &LT; HTML和GT;
  &LT; HEAD&GT;
  &LT; /头&GT;
  &LT;身体GT;
    &LT;对象的classid =clsid中:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B$​​ C $ CBase类=htt​​p://www.apple.com/qtactivex/qtplugin.cabWIDTH =300HEIGHT =50 &GT;
        &LT; PARAM NAME =SRCVALUE =htt​​p://translate.google.com/translate_tts?q=My+name+is+John&GT;
        &LT; PARAM NAME =自动播放VALUE =真&GT;
        &LT;嵌入型=音频/ X-WAVSRC =htt​​p://translate.google.com/translate_tts?q=My+name+is+John自动播放=真正的自动启动=真WIDTH = 300HEIGHT =50&GT;
    &LT; /对象&gt;
  &LT; /身体GT;
&LT; / HTML&GT;

I would want to hear the audio, when I click on an image (e.g. an audio image). The sound file for a sentence is obtained via google translate. I would like to do this without getting re-directed to a different page. How should I do this? I tried using the HTML5 audio tag, but didn't succeed either.

<html>
<body>
<a href="http://translate.google.com/translate_tts?q=My+name+is+John">My name is John</a>

</body>
</html>

解决方案

EDIT2

Here's another solution also posted on SO that may help you.


EDIT

A more robust solution. Tested in IE8 and Firefox

<html>
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
  </head>
  <body>
    <img src="http://www.blackwellokradio.com/click-me.jpg" onclick="$.sound.play('http://translate.google.com/translate_tts?q=My+name+is+John')" style="cursor:hand;cursor:pointer;" />
  </body>
</html>     
<!--Ideally you would put this in a separate file. src: http://dev.jquery.com/browser/trunk/plugins/sound/jquery.sound.js?rev=5750-->
<script type="text/javascript"> 
/**
 * jQuery sound plugin (no flash)
 * 
 * port of script.aculo.us' sound.js (http://script.aculo.us), based on code by Jules Gravinese (http://www.webveteran.com/) 
 * 
 * Copyright (c) 2007 Jörn Zaefferer (http://bassistance.de) 
 * 
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *   
 * $Id$
 */

/**
 * API Documentation
 * 
 * // play a sound from the url
 * $.sound.play(url)
 * 
 * // play a sound from the url, on a track, stopping any sound already running on that track
 * $.sound.play(url, {
 *   track: "track1"
 * });
 * 
 * // increase the timeout to four seconds before removing the sound object from the dom for longer sounds
 * $.sound.play(url, {
 *   timeout: 4000
 * });
 * 
 * // stop a sound by removing the element returned by play
 * var sound = $.sound.play(url);
 * sound.remove();
 * 
 * // disable playing sounds
 * $.sound.enabled = false;
 * 
 * // enable playing sounds
 * $.sound.enabled = true
 */

(function($) {

$.sound = {
    tracks: {},
    enabled: true,
    template: function(src) {
        return '<embed style="height:0" loop="false" src="' + src + '" autostart="true" hidden="true"/>';
    },
    play: function(url, options){
        if (!this.enabled)
            return;
        var settings = $.extend({
            url: url,
            timeout: 2000
        }, options);

        if (settings.track) {
            if (this.tracks[settings.track]) {
                var current = this.tracks[settings.track];
                // TODO check when Stop is avaiable, certainly not on a jQuery object
                current.Stop && current.Stop();
                current.remove();  
            }
        }

        var element = $.browser.msie
            ? $('<bgsound/>').attr({
                src: settings.url,
                loop: 1,
                autostart: true
              })
            : $(this.template(settings.url));

        element.appendTo("body");

        if (settings.track) {
            this.tracks[settings.track] = element;
        }

        if(options){
            setTimeout(function() {
                element.remove();
            }, options.timeout)
        }

        return element;
    }
};

})(jQuery);
</script>


Here's a way embedding Quicktime. You can just as easily use Windows Media Player...

<html>
  <head>
  </head>
  <body>
    <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="300" height="50">
        <param name="src" value="http://translate.google.com/translate_tts?q=My+name+is+John">
        <param name="autoplay" value="true">
        <embed type="audio/x-wav" src="http://translate.google.com/translate_tts?q=My+name+is+John" autoplay="true" autostart="true" width="300" height="50">
    </object>
  </body>
</html>   

这篇关于如何听到文本到语音翻译的音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆