HTML5から登場したAudioタグを使用して音を鳴らすサンプルアプリです。JavaScriptと組み合わせて、ボタンが押されたら再生するような記述例も盛り込んでいます。

サンプルプロジェクト

audio(Monaca用zip)

サンプルファイル

キーボードをカチャカチャたたく音
https://anko.education/wp-content/uploads/cacha.mp3
キーボードのエンターキーを激しくたたく音
https://anko.education/wp-content/uploads/tan.mp3

ソースコード


    <script>
        let cacha,tan;

        function load () {
            cacha = document.getElementById("cacha");
            tan = document.getElementById("tan");
            cacha.play();
        }
        function play () {
            tan.play();
        }

    </script>
</head>
<body onload="load()">
    <audio src="cacha.mp3" id="cacha" controls></audio>
    <audio src="tan.mp3" id="tan"></audio>
    <button onclick="play()">JavaScriptで再生</button>
</body>

表示例

Audioタグに関する解説

Audio(オーディオ)