alexylem / jarvis

Jarvis.sh is a simple configurable multi-lang assistant.
http://openjarvis.com
MIT License
800 stars 198 forks source link

Speaker/Mic selection by Name instead of Id #496

Open alexylem opened 7 years ago

alexylem commented 7 years ago

Change selection of Speaker/Mic during Installation / Settings to pick from Name instead of manually typing the card & decide Ids.

Thanks to @guillaumef

Using the card name is more reliable than using the id

You can get the name here:

$> cat /proc/asound/cards
 0 [HDMI           ]: HDA-Intel - HDA Intel HDMI
                      HDA Intel HDMI at 0xaa134000 irq 48
 1 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xaa130000 irq 46
 3 [AK5371         ]: USB-Audio - AK5371
                      AKM AK5371 at usb-0000:00:14.0-4.1.2, full speed

~/.asoundrc

pcm.!default {
  type asym
   playback.pcm {
     type plug
     slave.pcm { type hw card PCH }
   }
   capture.pcm {
     type plug
     slave.pcm { type hw card AK5371 }
   }
}
alexylem commented 7 years ago

I have doubts the card name will be enough. For example in my Raspberry Pi, for speakers, card ALSA has two devices, one for Jack and one for HDMI. So the card name does not seem to be discriminent.

$> aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$> cat /proc/asound/cards 
 0 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA
 1 [CameraB409241  ]: USB-Audio - USB Camera-B4.09.24.1
                      OmniVision Technologies, Inc. USB Camera-B4.09.24.1 at usb-3f980000.usb-1.5, hi
guillaumef commented 7 years ago

You can add 'device [INT] and subdevice [INT]' after card if needed. The card target goal with the string is still efficient with mixed sound hardware. But the subdevices will always be enumerated in the same order in a card.

Also, 'aplay' only displays the playback devices. It is not showing capture devices like dedicated usb microphone.

Another disruptive example is my desktop... for this, it is not efficient at all, i have 3 screens...

 0 [HDMI           ]: HDA-Intel - HDA Intel HDMI
                      HDA Intel HDMI at 0xf0510000 irq 28
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 0/1
  Subdevice #0: subdevice #0

The best of both world could be to:

alexylem commented 7 years ago

Yes to list capture devices I already use arecord -l I will do as suggested, mix of both if needed.

loteran commented 7 years ago

Hi everyone, I post here because i've got a problem with the AK5371 USB microphone. I need it for use with jarvis, before i try with my logitech webcam and everything work perfectly, but i have to speak too near from the webcam for be heard.

I use a raspberry 3 with OSMC

osmc@osmc:~$ lsb_release -a

No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 8.8 (jessie)
Release:        8.8
Codename:       jessie

So i buy an USB micro AK5371 this one :

So i plug it and go in the settings of jarvis but no sound detect.

So i do :

$> cat /proc/asound/cards

 GNU nano 2.2.6                  File: /proc/asound/cards

 0 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA
 1 [AK5371         ]: USB-Audio - AK5371
                      AKM AK5371 at usb-3f980000.usb-1.5, full speed

and :

$> aplay -l

**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

In .asoundrc, i was with hw1,0 (same than my webcam)

capture.pcm {
     type plug
     slave.pcm { type hw card AK5371 }

So i tried again jarvis and nothing change. So i check alsa mixer, choose the card and microphone, no problem, but when i try to record a wav for testing, nothing record ... i try to found some solutions but nothing work and i see you got the same microphone so i ask some help, because i can't believe is work on windows a

amixer

Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 26090 [40%] [on]
  Front Right: Playback 26090 [40%] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 65536
  Front Left: Capture 55696 [85%] [on]
  Front Right: Capture 55696 [85%] [on]

amixer -c 0

Simple mixer control 'PCM',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback -10239 - 400
  Mono: Playback -2000 [77%] [-20.00dB] [on]

amixer -c 1

Simple mixer control 'Mic',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 55
  Front Left: Capture 51 [93%] [20.00dB] [on]
  Front Right: Capture 51 [93%] [20.00dB] [on]

arecord -l

**** List of CAPTURE Hardware Devices ****
card 1: AK5371 [AK5371], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

PS : the microphone work directly when i plug it in my computer (windows) and not on linux ;) Thanks for your help and sorry for my english, i'm french ^^

If you need other information, just tell me ;)

PS2: I found the Alsa script for information of my raspberry :

upload=true&script=true&cardinfo=
!!################################
!!ALSA Information Script v 0.4.61
!!################################
!!Script ran on: Wed May 31 14:51:14 UTC 2017
!!Linux Distribution
!!------------------
ID_LIKE=debian

!!DMI Information
!!---------------
Manufacturer:      
Product Name:      
Product Version:   
Firmware Version:  

!!Kernel Information
!!------------------
Kernel release:    4.4.27-9-osmc
Operating System:  GNU/Linux
Architecture:      armv7l
Processor:         unknown
SMP Enabled:       Yes

!!ALSA Version
!!------------
Driver version:     k4.4.27-9-osmc
Library version:    1.0.28
Utilities version:  1.0.28

!!Loaded ALSA modules
!!-------------------
snd_bcm2835
snd_usb_audio

!!Sound Servers on this system
!!----------------------------
Pulseaudio:
      Installed - Yes (/usr/bin/pulseaudio)
      Running - Yes

!!Soundcards recognised by ALSA
!!-----------------------------

 0 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA
 1 [AK5371         ]: USB-Audio - AK5371
                      AKM AK5371 at usb-3f980000.usb-1.5, full speed

!!PCI Soundcards installed in the system
!!--------------------------------------

!!Advanced information - PCI Vendor/Device/Subsystem ID's
!!-------------------------------------------------------

!!Modprobe options (Sound related)
!!--------------------------------
snd_pcsp: index=-2
snd_usb_audio: index=-2
snd_atiixp_modem: index=-2
snd_intel8x0m: index=-2
snd_via82xx_modem: index=-2

!!Loaded sound module options
!!---------------------------
!!Module: snd_bcm2835
    force_bulk : N

!!Module: snd_usb_audio
    autoclock : Y
    device_setup : 0,0,0,0,0,0,0,0
    enable : Y,Y,Y,Y,Y,Y,Y,Y
    id : (null),(null),(null),(null),(null),(null),(null),(null)
    ignore_ctl_error : N
    index : -2,-1,-1,-1,-1,-1,-1,-1
    pid : -1,-1,-1,-1,-1,-1,-1,-1
    vid : -1,-1,-1,-1,-1,-1,-1,-1

!!USB Mixer information
!!---------------------
--startcollapse--

USB Mixer: usb_id=0x05560002, ctrlif=0, ctlerr=0
Card: AKM AK5371 at usb-3f980000.usb-1.5, full speed
  Unit: 3
    Control: name="Mic Capture Volume", index=0
    Info: id=3, control=2, cmask=0x3, channels=2, type="S16"
    Volume: min=-7936, max=6144, dBmin=-3100, dBmax=2400
  Unit: 3
    Control: name="Mic Capture Switch", index=0
    Info: id=3, control=1, cmask=0x0, channels=1, type="INV_BOOLEAN"
    Volume: min=0, max=1, dBmin=0, dBmax=0
--endcollapse--

!!ALSA Device nodes
!!-----------------
crw-rw---- 1 root audio 116,  0 May 31 15:30 /dev/snd/controlC0
crw-rw---- 1 root audio 116, 32 May 31 15:40 /dev/snd/controlC1
crw-rw---- 1 root audio 116, 16 May 31 15:30 /dev/snd/pcmC0D0p
crw-rw---- 1 root audio 116, 17 May 31 15:30 /dev/snd/pcmC0D1p
crw-rw---- 1 root audio 116, 56 May 31 15:40 /dev/snd/pcmC1D0c
crw-rw---- 1 root audio 116,  1 May 31 15:30 /dev/snd/seq
crw-rw---- 1 root audio 116, 33 May 31 15:30 /dev/snd/timer

/dev/snd/by-id:
total 0
drwxr-xr-x 2 root root  60 May 31 15:40 .
drwxr-xr-x 4 root root 220 May 31 15:40 ..
lrwxrwxrwx 1 root root  12 May 31 15:40 usb-AKM_AK5371-00 -> ../controlC1

/dev/snd/by-path:
total 0
drwxr-xr-x 2 root root  60 May 31 15:40 .
drwxr-xr-x 4 root root 220 May 31 15:40 ..
lrwxrwxrwx 1 root root  12 May 31 15:40 platform-3f980000.usb-usb-0:1.5:1.0 -> ../controlC1

!!ALSA configuration files
!!------------------------
!!User specific config file (~/.asoundrc)

pcm.!default {
  type asym
   playback.pcm {
     type plug
     slave.pcm "hw:0,0"
   }
   capture.pcm {
     type plug
     slave.pcm "hw:1,0"
   }
}

!!Aplay/Arecord output
!!--------------------

APLAY

**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 7/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

ARECORD

**** List of CAPTURE Hardware Devices ****
card 1: AK5371 [AK5371], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

!!Amixer output
!!-------------

!!-------Mixer controls for card 0 [ALSA]

Card hw:0 'ALSA'/'bcm2835 ALSA'
  Mixer name    : 'Broadcom Mixer'
  Components    : ''
  Controls      : 6
  Simple ctrls  : 1
Simple mixer control 'PCM',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback -10239 - 400
  Mono: Playback -2000 [77%] [-20.00dB] [on]

!!-------Mixer controls for card 1 [AK5371]

Card hw:1 'AK5371'/'AKM AK5371 at usb-3f980000.usb-1.5, full speed'
  Mixer name    : 'USB Mixer'
  Components    : 'USB0556:0002'
  Controls      : 3
  Simple ctrls  : 1
Simple mixer control 'Mic',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 55
  Front Left: Capture 51 [93%] [20.00dB] [on]
  Front Right: Capture 51 [93%] [20.00dB] [on]

!!Alsactl output
!!--------------

--startcollapse--
state.ALSA {
    control.1 {
        iface MIXER
        name 'PCM Playback Volume'
        value -2000
        comment {
            access 'read write'
            type INTEGER
            count 1
            range '-10239 - 400'
            dbmin -9999999
            dbmax 400
            dbvalue.0 -2000
        }
    }
    control.2 {
        iface MIXER
        name 'PCM Playback Switch'
        value true
        comment {
            access 'read write'
            type BOOLEAN
            count 1
        }
    }
    control.3 {
        iface MIXER
        name 'PCM Playback Route'
        value 1
        comment {
            access 'read write'
            type INTEGER
            count 1
            range '0 - 2'
        }
    }
    control.4 {
        iface PCM
        name 'IEC958 Playback Default'
        value '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
        comment {
            access 'read write'
            type IEC958
            count 1
        }
    }
    control.5 {
        iface PCM
        name 'IEC958 Playback Con Mask'
        value '0200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
        comment {
            access read
            type IEC958
            count 1
        }
    }
    control.6 {
        iface PCM
        name 'IEC958 Playback PCM Stream'
        value '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
        comment {
            access 'read write inactive'
            type IEC958
            count 1
        }
    }
}
state.AK5371 {
    control.1 {
        iface PCM
        name 'Capture Channel Map'
        value 0
        comment {
            access read
            type INTEGER
            count 1
            range '0 - 36'
        }
    }
    control.2 {
        iface MIXER
        name 'Mic Capture Switch'
        value true
        comment {
            access 'read write'
            type BOOLEAN
            count 1
        }
    }
    control.3 {
        iface MIXER
        name 'Mic Capture Volume'
        value.0 51
        value.1 51
        comment {
            access 'read write'
            type INTEGER
            count 2
            range '0 - 55'
            dbmin -3100
            dbmax 2400
            dbvalue.0 2000
            dbvalue.1 2000
        }
    }
}
--endcollapse--

!!All Loaded Modules
!!------------------

Module
arc4
ecb
md4
hmac
bnep
hci_uart
btbcm
bluetooth
8021q
garp
stp
llc
nls_utf8
cifs
brcmfmac
brcmutil
snd_usb_audio
snd_hwdep
cfg80211
snd_usbmidi_lib
snd_rawmidi
rfkill
snd_seq_device
bcm2835_thermal
bcm2835_wdt
snd_bcm2835
snd_pcm
snd_timer
snd
bcm2835_gpiomem
uio_pdrv_genirq
uio
fuse
ipv6

!!ALSA/HDA dmesg
!!--------------