alphacep/vosk-asterisk

how to get variable from extensions.conf

Natphitchayuk opened this issue · 7 comments

in extensions.conf
same = n,Set(SPEECH_ENGINE(VOSK_CONFIG)={"config" : {""}}

how to get VOSK_CONFIG in res_speech_vosk.c

I have tried to use ast_variable_retrieve but it has not worked for me.

#define EXTENSIONS_CONFIG "/etc/asterisk/extensions.conf"
struct ast_flags config_flags = { 0 };
struct ast_config *cfg = ast_config_load(EXTENSIONS_CONFIG, config_flags);
const char *value = NULL;
if((value = ast_variable_retrieve(cfg, "from-internal", "VOSK_CONFIG")) != NULL) {
	ast_log(LOG_DEBUG, "from-internal.config=%s\n", value);
	vosk_engine.config = ast_strdup(value);
}

Something like this, yes. You'd better pass arguments as parameters to the engine, not through variable. You can substitute variable in parameters in speech command if you need them.

Can you please give me SOME examples?

You'd better describe what you want to implement overall, why do you need to change config.

I added max_speech_timeout & complete_timeout to asr_server.py. (vosk-server)

        message = await websocket.recv()
        if isinstance(message, str) and 'config' in message:
            jobj = json.loads(message)['config']
            logging.info("Config %s", jobj)
            if 'phrase_list' in jobj:
                phrase_list = jobj['phrase_list']
            if 'sample_rate' in jobj:
                sample_rate = float(jobj['sample_rate'])
            if 'words' in jobj:
                show_words = bool(jobj['words'])
            if 'max_alternatives' in jobj:
                max_alternatives = int(jobj['max_alternatives'])
            if 'max_speech_timeout' in jobj:
                max_speech_timeout = now + datetime.timedelta(seconds=float(jobj['max_speech_timeout']))
            if 'complete_timeout' in jobj:
                complete_timeout = datetime.timedelta(seconds=float(jobj['complete_timeout']))
            continue

and send config with ast_websocket_write_string
(res-speech-vosk.c)

vosk_engine.config = ast_strdup("{\"config\" : { \"max_speech_timeout\" : 10, \"complete_timeout\" : 2.5 } }");
ast_websocket_write_string(vosk_speech->ws,vosk_engine.config);

how to obtain VOSK_CONFIG (extensions.conf) on res_speech_vosk.c

same = n,Set(SPEECH_ENGINE(VOSK_CONFIG)={"config" : { "max_speech_timeout" : 20, "complete_timeout" : 5 } })

I want to set a different timeout for each input. For example,

  1. When I ask for address the timeout should be 10 seconds
  2. When I ask for phone number the time should only be 5 seconds.
exten   = 5,1,Answer
same    = n,Wait(1)
same 	= n,Set(SPEECH_ENGINE(VOSK_CONFIG)={"config" : { "max_speech_timeout" : 20, "complete_timeout" : 20 } })
same    = n,SpeechCreate
same    = n,SpeechBackground(hello, 30)
same    = n,Verbose(0,Result      : ${SPEECH(results})
same    = n,Verbose(0,Status      : ${SPEECH(status)})
same    = n,Verbose(0,Spoke       : ${SPEECH(spoke)})
same    = n,Verbose(0,Transcribe  : ${SPEECH_TEXT(0)})
same    = n,SpeechDestroy
same 	= n,Set(SPEECH_ENGINE(VOSK_CONFIG)={"config" : { "max_speech_timeout" : 5, "complete_timeout" : 5 } })
same    = n,SpeechCreate
same    = n,SpeechBackground(hello, 30)
same    = n,Verbose(0,Result      : ${SPEECH(results})
same    = n,Verbose(0,Status      : ${SPEECH(status)})
same    = n,Verbose(0,Spoke       : ${SPEECH(spoke)})
same    = n,Verbose(0,Transcribe  : ${SPEECH_TEXT(0)})
same    = n,SpeechDestroy

Hello @Natphitchayuk
Have you successfully implemented vosk server with asterisk.
we facing some issue with integration.
pls share steps.