roboticslab-uc3m / speech

Text To Speech (TTS) and Automatic Speech Recognition (ASR).
https://robots.uc3m.es/speech/
GNU Lesser General Public License v2.1
4 stars 4 forks source link

[speechRecognition.py] Research on muting microphone #13

Closed jgvictores closed 2 years ago

jgvictores commented 6 years ago

Research on muting microphone. Several Python multiplatform solutions, but right now need c++ on Ubuntu. Here are some references. I believe we are using ALSA, not pulseaudio, so will check first option.

  1. https://askubuntu.com/questions/26068/how-do-you-mute-from-the-command-line
  2. https://stackoverflow.com/questions/3985014/linux-alsa-sound-api-questions-how-do-you-mute
jgvictores commented 6 years ago

Better:

amixer -c 1 sset Mic nocap
amixer -c 1 sset Mic cap

Ref:

rsantos88 commented 6 years ago

I've been checking this lines but it doesn't work. When I put this line, it shows:

amixer: Unable to find simple control 'Mic',0

So, I've tried to put my control, checking first with amixer scontrols

Simple mixer control 'IEC958',0

but it doesn't recognize nocap or cap command:

amixer: Invalid command!

Other option is using alsamixer but as indicated in this discussion it's not working when we try to muting/turning down the mic. The only way that I found for mute it is changing the Input Source to another that is not connected (for example Rear Mic)

jgvictores commented 6 years ago

Okay, maybe this is pretty platform-specific and on future comments we should document on which system (PC, distro, version) each specific command was working. :sweat_smile:

rsantos88 commented 6 years ago

From tiago-main t1-barcelona-microphone branch:

        res = system ("amixer -c 1 sset Mic cap");
        cout << "--Microphone ON--" << endl;

        while (!speechRecognitionPort.read(bot, false));

        res = system ("amixer -c 1 sset Mic nocap");
        cout << "--Microphone OFF--" << endl;
rsantos88 commented 6 years ago

Project https://github.com/larsimmisch/pyalsaaudio looks interesting for speechRecognition.py. Can be installed easily:

sudo apt install libasound2-dev
pip install pyalsaaudio --user

And run example mixertest.py.

rsantos88 commented 6 years ago

Possible idea for mute the microphone:

* [terminal 1] speechRecognition.py
* [terminal 2] yarp rpc /speechRecognition/rpc:s
>> setMic mute 
>> setMic unmute

using this port allow us to mute the microphone running the demostration (follow-me, waiter...) when it is necessary, e.g when the robot is speaking or doing some action and we want to avoid the noise.

rsantos88 commented 6 years ago

implemented and working at (#18)

rsantos88 commented 6 years ago

ToDo: to adapt the demostrations with this functionality (follow-me and teo-waiter)

rsantos88 commented 6 years ago

Problem fixed and interesting to document: I've been installing the bluetooth microphone and I found some problems to see the device once it was paired in sound settings->input. In that case, I put this command: sudo -H pactl load-module module-bluetooth-discover trying to load the pulseaudio module. If you see this error:

Failure: Module initialization failed

Solution:

sudo apt-get install pulseaudio-module-bluetooth
rsantos88 commented 6 years ago

summary to do:

rsantos88 commented 6 years ago
  • [ ] Prepare teo-head to use microphone bluetooth

At this point, I found that teo-head include a internal bluetooth receiver. This is recognized and automatically activated by the O.S but it has a very poor coverage. So, I want to add the usb-bluetooth. I need to know how to disable the internal bluetooth and enable only the usb-bluetooth detection.

rsantos88 commented 6 years ago

To show a list of this devices: rfkill list all

rsantos88 commented 6 years ago
  • [x] Prepare teo-head to use microphone bluetooth

At this point, I found that teo-head include a internal bluetooth receiver. This is recognized and automatically activated by the O.S but it has a very poor coverage. So, I want to add the usb-bluetooth. I need to know how to disable the internal bluetooth and enable only the usb-bluetooth detection.

I resolved this problem. I'll put here the steps:

  1. See the devices. Should be some on the Intel devices.
    In this case : Bus 003 Device 003: ID 8087:07da Intel Corp
    lsusb
    Bus 002 Device 002: ID 8087:8000 Intel Corp. 
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 002: ID 8087:8008 Intel Corp. 
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 003 Device 002: ID 046a:0010 Cherry GmbH SmartBoard XX44
    Bus 003 Device 003: ID 8087:07da Intel Corp. 
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  2. Disable this device here:
    sudo nano /etc/udev/rules.d/81-bluetooth-hci.rules

    and pasting this

    SUBSYSTEM=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="07da", ATTR{authorized}="0"

    Save, exit nano and reboot

rsantos88 commented 6 years ago

Once all the above is done, a new error found... it shows:

sudo -H pactl load-module module-bluetooth-discover
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

No input sound device found :(

rsantos88 commented 6 years ago
  • [x] Prepare demostrations to use mute/unmute functionality

Here we've a limitation. We can mute or unmute the microphone by software automatically, sending the demonstration commands to speechRecognition when the robot is speaking or in a moments when we know for sure we're not going to talk. But, the problem here is what happen when the robot is waiting for an order and at the same time is doing something. E.g: Teo is following you but it's checking all the time if you are going to say "stop". Here, we can take the option to mute all the time the microphone, but we can't stop him by command voice. If we don't mute the microphone, Teo will receive to much noise and false orders.

At this point, any possible idea of how to resolve that with the work done ?

PeterBowman commented 6 years ago

One thing I can come up with are acknowledgements. That is, make TEO send an Are you sure? notice back to you, and await confirmation. Is it feasible in your demo workflow?

rsantos88 commented 6 years ago

One thing I can come up with are acknowledgements. That is, make TEO send an Are you sure? notice back to you, and await confirmation. Is it feasible in your demo workflow?

Yes, it's feasible but in practice, Teo would be all the time trying to await confirmation or receiving wrong inputs.

rsantos88 commented 6 years ago

Other possible idea is to filter the noise with greater concatenation of words: E.g please stop TEO instead of stop but I want to get a solution to avoid modifying the dictionaries...

rsantos88 commented 6 years ago

Note: to restart audio devices sudo /etc/init.d/pulseaudio restart

rsantos88 commented 6 years ago

related: https://github.com/roboticslab-uc3m/teo-hardware-issues/issues/29

jgvictores commented 5 years ago

@rsantos88 What should be do with this issue?

  1. Consider it blocked by https://github.com/roboticslab-uc3m/teo-hardware-issues/issues/29 ?
  2. Leave it open until we document the conclusions/recommendations at https://github.com/roboticslab-uc3m/developer-manual ?
PeterBowman commented 1 year ago

Another take on this through Python's sounddevice package: 2dd945939c7142d374912b4a5a5dee130724872c.