User Tools

Site Tools


Sidebar

en:objects:sound:sound_file:recognize_file

recognize_file

recognize_file($path,$dict,$jsgf,$hmm,$add_params="",$timeout=60); - recognize an audio file as speech using the Open Source Speech Recognition Toolkit CMU Sphinx (Available from version 4.10.7)
- the file must have a resolution of 128 Kb/s (8 kHz) ( you can Change the file format via $sound->convert_file )

The function accepts parameters as input:

  • $path – path to the audio file to be recognized (wav format, sampling must meet the sampling requirements of the model used)
  • $dict – dictionary path (the path must be relative to the Audio Tools folder)
  • $jsgf – path to the gramatics file (format JSGF (the path must be relative to the Audio Tools folder)
  • $hmm – directory path hmm models (the path must be relative to the Audio Tools folder)
  • $add_params – additional command-line parameters to run pocketsphinx_continuous.exe
  • $timeout – maximum time allowed for this operation

    After testing, the function returns the result of its work to the script :
  • true – a sequence of numbers dictated in the audio file (separated by a space)
  • false – the operation was not completed successfully

    PHP example:

    <?php $xhe_host = "127.0.0.1:7010";
     
    //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.Prepare the file:";
    echo $sound->convert_file("test/mp3/4196092774.mp3", "test/mp3/4196092774.wav", "8000")." n";
     
    //2
    echo "2.Recognize the file with English numbers(0-9) using CMU Sphinx:";
    echo $sound->recognize_file("test/mp3/4196092774.wav", "digits \ digits.dict", "digits \ digits.gram", "cmusphinx-en-us-8khz-5.2", "- samprate 8000 -remove_dc yes -remove_noise no -vad_threshold 3.4 -vad_prespeech 19 -vad_postspeech 37 -silprob 2.5 ")."  N ";
     
    //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.Prepare the file:")
    echo(sound.convert_file("test/mp3/4196092774.mp3", "test/mp3/4196092774.wav", "8000"), "
    ")
     
    # 2
    echo("2.Recognize file with English numbers(0-9) using CMU Sphinx:")
    echo(sound.recognize_file("test/mp3/4196092774.wav", "digits \ digits.dict", "digits \ digits.gram", "cmusphinx-en-us-8khz-5.2", "- samprate 8000 -remove_dc yes -remove_noise no -vad_threshold 3.4 -vad_prespeech 19 -vad_postspeech 37 -silprob 2.5 "),"
    ")
     
    # 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:7021";
    InitXHE();
     
    //Start
    echo("<hr> <font color = blue> sound.recognize_file </font> <hr>");
     
    //1
    echo("1.Prepare the file:");
    echo(sound.convert_file("test/mp3/4196092774.mp3", "test/mp3/4196092774.wav", "8000") + " n");
     
    //2
    echo("2.Recognize the file with English numbers(0-9) using CMU Sphinx:");
    echo(sound.recognize_file("test/mp3/4196092774.wav", "digits \ digits.dict", "digits \ digits.gram", "cmusphinx-en-us-8khz-5.2", "- samprate 8000 -remove_dc yes -remove_noise no -vad_threshold 3.4 -vad_prespeech 19 -vad_postspeech 37 -silprob 2.5 ") +"  n ");
     
    //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.Prepare the file:");
    echo(sound.convert_file("test/mp3/4196092774.mp3", "test/mp3/4196092774.wav", "8000") + " n");
     
    //2
    echo("2.Recognize the file with English numbers(0-9) using CMU Sphinx:");
    echo(sound.recognize_file("test/mp3/4196092774.wav", "digits \ digits.dict", "digits \ digits.gram", "cmusphinx-en-us-8khz-5.2", "- samprate 8000 -remove_dc yes -remove_noise no -vad_threshold 3.4 -vad_prespeech 19 -vad_postspeech 37 -silprob 2.5 ") +"  n ");
     
    //end
    echo("<hr> <br>");
     
    //Quit
    app.quit();
  • en/objects/sound/sound_file/recognize_file.txt · Last modified: 2020/10/14 12:52 (external edit)