Python et mycroft-config

Bonjour, je souhaite créer un programme python qui changerait la langue de mycroft.

Quelqu’un saurait-il comment je peux exécuter "mycroft-config set lang ‘xx-xx’ " dans un programme python?

1 Like

Hi Olivier,

Before answering your question I’d flag that setting that language config won’t configure all of the Mycroft components to work in another language. There’s some extra work that needs to be done to achieve this. You can find more info in our documentation:
https://mycroft-ai.gitbook.io/docs/using-mycroft-ai/customizations/languages

To directly answer your question about how to issue bash commands from Python, I’d use:

import subprocess

command = ['mycroft-config', 'set', 'lang', 'xx-xx']
process = subprocess.Popen(command)

There’s a whole lot on the internet about the difference between:

  • subprocess.Popen
  • subprocess.call
  • subprocess.run

I think subprocess.run() is actually the recommended method now, I’m just used to Popen.

Hello, thank you very much for your answer, it’s really nice. I will try this and tell you if it works. Have a good day!

Good evening,

i try this code:

import os
import subprocess

os.chdir(’/home/pi/mycroft-core’)

command = [‘mycroft-config’, ‘set’, ‘lang’, ‘en-us’]
process = subprocess.Popen(command, shell =True)

This return an error:
set: 1: set: mycroft-config: not found

one idea?

Thanks.

Oliver

The subprocess run because when I put command = [‘ls’, ‘-l’], i have a result

sounds like the mycroft helper commands aren’t on your $PATH

You can call it directly eg:
/home/user/mycroft-core/bin/mycroft-config set lang en-us

Or add the mycroft-core/bin directory to your $PATH
that link ^^ was just the first result from DDG

I also assume you don’t need shell=True and you should avoid using that unless you do need it

Thank you again. I have already checked $PATH when I saw ERROR

(.venv) pi@picroft:~ $ echo $PATH
/home/pi/bin:/home/pi/mycroft-core/.venv/bin:/home/pi/bin:/home/pi/mycroft-core/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/mycroft-core/bin

It seems to be good.

The virtual environnement should be the reason?

I will search again.

I m a student and I work on a personnal project based on Mycroft. It’s very interesting but sometimes hard. I will show my project in 10 days to a jury.

Thanks again.

I changed method. I make a script .sh .
It works

#!/usr/bin/env bash

cd /home/pi/mycroft-core/bin/

bash ./mycroft-config set lang “en-us”
bash ./mycroft-config set tts.google.lang “en-us”
bash ./mycroft-config set stt.mycroft.lang “en-us”

cd /home/pi/mycroft-core/

bash ./start-mycroft.sh restart all

1 Like