Sidebar

en:objects:sound:sound_file:convert_file

convert_file

convert_file($src_path,$new_path,$Hz="",$timeout=60); - this function is used to convert an audio file to another format (Available from version 4.10.7)

The function accepts parameters as input:

  • $src_path – path to the audio file to convert
  • $new_path – path where the converted audio file will be written
  • $Hz – digitization frequency in Hz (if not specified, the current one will be used)
  • $timeout – maximum time allowed for this operation

    After testing, the function returns the result of its work to the script :
  • true – successfully converted the audio file (boolean)
  • false – operation failed (boolean)

    PHP example:

    <?php $xhe_host = "127.0.0.1:7062";
     
    //connect the object to control the emulator, if not already connected
    if(!isset($path))
       $path = "../../../Templates/xweb_human_emulator.php";
    require($path);
     
    //Start
    echo "<hr> <font color = blue> sound->".basename(__FILE__)."</font> <hr>";
     
    //1
    echo "1.Change the format of the mp3 file to flac:";
    echo $sound->convert_file("test/mp3/68323.mp3", "test/audio.flac")." n";
     
    //2
    echo "2.Change the format of the mp3 file to wav 8 kHz:";
    echo $sound->convert_file("test/mp3/68323.mp3", "test/audio8.wav", "8000");
     
    //end
    echo "<hr> <br>";
     
    //Quit
    $app->quit();
    ?>

    Python example:

    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
     
    xhe_host = "127.0.0.1:7010"
    from xweb_human_emulator import *
     
    # Start
    echo("<hr> <font color = blue> sound.xxxxxxxxx </font> <hr>")
     
    # 1
    echo("1.Change the format of the mp3 file to flac:")
    echo(sound.convert_file("test/mp3/68323.mp3", "test/audio.flac"), "
    ")
     
    # 2
    echo("2.Change the format of the mp3 file to wav:")
    echo(sound.convert_file("test/mp3/4196092774.mp3", "test/4196092774.wav", "8000"))
     
    # end
    echo("<hr> <br>")
     
    # Quit
    app.quit()

    C# example:

    #region using
     
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
     
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
     
    #endregion
     
      class Program: XHEScript
      {
    static void Main(string [] args)
    {
    //init XHE
    server = "127.0.0.1:7022";
    InitXHE();
     
    //Start
    echo("<hr> <font color = blue> sound.convert_file </font> <hr>");
     
    //1
    echo("1.Let's change the format of the mp3 file to flac:");
    echo(sound.convert_file("test/mp3/68323.mp3", "test/audio.flac") + " n");
     
    //2
    echo("2.Let's change the format of the mp3 file to wav 8 kHz:");
    echo(sound.convert_file("test/mp3/68323.mp3", "test/audio_8.wav", "8000"));
     
    //end
    echo("<hr> <br>");
     
    app.quit();
    }
    }

    Java Script example:

    //connect the object to control the emulator, if not already connected
    xhe_host = "127.0.0.1:7022";
    echo = require("../../../Templates JS/xweb_human_emulator.js");
     
    //Start
    echo("<hr> <font color = blue> sound.play_sound </font> <hr>");
     
    //1
    echo("1.Let's change the format of the mp3 file to flac:");
    echo(sound.convert_file("test/mp3/68323.mp3", "test/audio.flac") + " n");
     
    //2
    echo("2.Let's change the format of the mp3 file to wav 8 kHz:");
    echo(sound.convert_file("test/mp3/68323.mp3", "test/audio_8.wav", "8000"));
     
    //end
    echo("<hr> <br>");
     
    //Quit
    app.quit();
  • en/objects/sound/sound_file/convert_file.txt · Last modified: 2026/08/05 22:47 (external edit)