Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get variable from extensions.conf #26

Open
Natphitchayuk opened this issue May 11, 2022 · 7 comments
Open

how to get variable from extensions.conf #26

Natphitchayuk opened this issue May 11, 2022 · 7 comments

Comments

@Natphitchayuk
Copy link

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.

@Natphitchayuk
Copy link
Author

#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);
}

@nshmyrev
Copy link
Contributor

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.

@Natphitchayuk
Copy link
Author

Can you please give me SOME examples?

@nshmyrev
Copy link
Contributor

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

@Natphitchayuk
Copy link
Author

Natphitchayuk commented May 11, 2022

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 } })

@Natphitchayuk
Copy link
Author

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

@helpinghandindia1
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants