alphacep / vosk-server

WebSocket, gRPC and WebRTC speech recognition server based on Vosk and Kaldi libraries
Apache License 2.0
882 stars 243 forks source link

Getting different outputs in php client samples #161

Open James9760 opened 2 years ago

James9760 commented 2 years ago

I'm running this code in vosk-server/client-samples/php/asr-test passing the same file that i am passing to python client but this file is not returning correct output it is different from the output that i have got with python script.

require_once("./vendor/autoload.php");

use WebSocket\Client;

$client = new Client("ws://localhost:2700/", array('timeout' => 20000));
$myfile = fopen("test.wav", "rb");
while(!feof($myfile)) {
   $data = fread($myfile, 8000);
   $client->send($data, 'binary');
   echo $client->receive() . "\n";
}
$client->send("{\"eof\" : 1}");
echo $client->receive() . "\n";
fclose($myfile);

?>

Output :

{ "partial" : "" } { "text" : "" }

python output : {"result": [{"conf": 0.584788, "end": 5.039281, "start": 4.86, "word": "test"}, "test"]}

nshmyrev commented 2 years ago

It is a sample rate issue, you need to configure sample rate with a config message probably.

James9760 commented 2 years ago

I have to send sample rate parameter in php file same as done in python script

 await websocket.send('''{"config" : 
                        { "phrase_list" : ["zero one two three four five", "six seven eight nine oh"],
                        "sample_rate" : %d,
                        "words" : 0}}''' % (wf.getframerate()))

asr_server.py

 args.interface = os.environ.get('VOSK_SERVER_INTERFACE', '0.0.0.0')
    args.port = int(os.environ.get('VOSK_SERVER_PORT', 2700))
    args.model_path = os.environ.get('VOSK_MODEL_PATH', 'model')
    args.spk_model_path = os.environ.get('VOSK_SPK_MODEL_PATH')
    args.sample_rate = float(os.environ.get('VOSK_SAMPLE_RATE', 8000))
    args.max_alternatives = int(os.environ.get('VOSK_ALTERNATIVES', 0))
    args.show_words = bool(os.environ.get('VOSK_SHOW_WORDS', True))

by default sample rate is set to 8000