0

I have been researching into using PHP and Javascript to communicate with each other on the same page.

Firstly I have a php script at the top with a function to retrieve a audio from an AWS Ivona media stream.

<?php
    function createAndPlay($text){
        // request service get response save to `$data`
        // I want this to then play the sound
    }
?>

<script>
// when button clicked createAndPlay("Text to Speak")
<script>

I would like this to be done on the same page WITHOUT starting when the body of the document is first loaded.

4

1 回答 1

0

根据你的最后一句话:

我希望在第一次加载文档正文时不开始在同一页面上完成此操作。

听起来您的情况是所有这些都正常工作,但是当您加载页面时音频会自动播放。<script>考虑到您将电话放在标签中,这是有道理的。Javascript 将在看到它并播放音频后立即处理它。很难说,因为您没有包含该实际代码。

您需要将script块移动到链接或按钮或其他东西:

 <a href="#" onclick='createAndPlay("Text to Speak");'>Click to hear</a>
于 2016-10-05T14:29:17.743 回答