如何听到文本到语音翻译的音频

发布于 2024-09-26 10:39:01 字数 283 浏览 1 评论 0原文

当我单击图像(例如音频图像)时,我想听到音频。句子的声音文件是通过谷歌翻译获得的。我想在不重定向到其他页面的情况下执行此操作。我该怎么做?我尝试使用 HTML5 音频标签,但也没有成功。

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

</body>
</html>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别理我 2024-10-03 10:39:01

编辑2

这是另一个解决方案< /a> 也发布在 SO 上,可能会对您有所帮助。


编辑

更强大的解决方案。在 IE8 和 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>

这是一种嵌入 Quicktime 的方法。您可以轻松使用 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>   

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>   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文