jasperproject / jasper-client

Client code for Jasper voice computing platform
MIT License
4.53k stars 1.01k forks source link

stuttering sound output in devel-branch #592

Open bruxi opened 7 years ago

bruxi commented 7 years ago

Hi,

just cloned the devel-branch onto my Raspi 3. Everything works fine, but the sound output via the jack sounds very stuttering and slow. When I play the sounds with aplay oder mplayer everything sounds ok. The official jasper-client works perfect as well. So the actual sound configuration doesn't seem to be the problem.

Jasper itself lists the following sound devices, I tried default and gave bcm2835-alsa-hw-10 explicitly with no change.

[Audio device 'usb-audio-device-hw-00']
  Name: USB Audio Device: - (hw:0,0)
  Input device: Yes
  Output device: No
[Audio device 'bcm2835-alsa-hw-10']
  Name: bcm2835 ALSA: - (hw:1,0)
  Input device: No
  Output device: Yes
[Audio device 'bcm2835-alsa-iec958-hdmi']
  Name: bcm2835 ALSA: IEC958/HDMI (hw:1,1)
  Input device: No
  Output device: Yes
[Audio device 'sysdefault']
  Name: sysdefault
  Input device: Yes
  Output device: No
[Audio device 'spdif']
  Name: spdif
  Input device: Yes
  Output device: No
[Audio device 'default']
  Name: default
  Input device: No
  Output device: Yes

Any ideas?

torbenbrodt commented 7 years ago

Hi, maybe the ideas in #404 help you

bruxi commented 7 years ago

Hi, thanks for the hint. I increased the value to 8192 and now it sounds much better but not good. Found some other hints that the builtin sound of Raspi is not that good. That's true because I always have a noise in the speakers. Have ordered an USB mini soundcard and will continue testing with it.

G10DRAS commented 7 years ago

Try audio_engine: alsa

There is no problem with builtin sound card.

bruxi commented 7 years ago

with audio_engine: alsa

I get:

Traceback (most recent call last):
  File "./Jasper.py", line 5, in <module>
    jasper.main()
  File "/home/pi/jasper2/jasper-client/jasper/__main__.py", line 48, in main
    batch_file=p_args.batch_file)
  File "/home/pi/jasper2/jasper-client/jasper/application.py", line 128, in __init__
    category='audioengine')
  File "/home/pi/jasper2/jasper-client/jasper/pluginstore.py", line 215, in get_plugin
    raise PluginError("Plugin '%s' not found!" % name)
jasper.pluginstore.PluginError: Plugin 'alsa' not found!
G10DRAS commented 7 years ago

Not sure about the issue, try running it with --debug flag and you will see more messages like

AUDIO  <alsa_1_0_0.alsaaudioengine.AlsaAudioEnginePlugin object at 0x1de7410>
DEBUG:alsa_1_0_0.alsaaudioengine:Found 11 ALSA devices
DEBUG:alsa_1_0_0.alsaaudioengine:Found 13 ALSA devices
DEBUG:alsa_1_0_0.alsaaudioengine:Found 5 ALSA devices
DEBUG:alsa_1_0_0.alsaaudioengine:Found 13 ALSA devices

DEBUG:jasper.mic:Input sample rate: 16000 Hz
DEBUG:jasper.mic:Input sample width: 16 bit
DEBUG:jasper.mic:Input channels: 1
DEBUG:jasper.mic:Input chunksize: 1024 frames
DEBUG:jasper.mic:Output chunksize: 320 frames
DEBUG:jasper.mic:Output padding: no

DEBUG:alsa_1_0_0.alsaaudioengine:output stream opened on device 'front-card-alsa' (16000 Hz, 1 channel, 16 bit)
DEBUG:alsa_1_0_0.alsaaudioengine:output stream closed on device 'front-card-alsa'
DEBUG:alsa_1_0_0.alsaaudioengine:input stream opened on device 'front-card-u0x46d0x825' (16000 Hz, 1 channel, 16 bit)
DEBUG:alsa_1_0_0.alsaaudioengine:input stream closed on device 'front-card-u0x46d0x825'
DEBUG:alsa_1_0_0.alsaaudioengine:output stream opened on device 'front-card-alsa' (44100 Hz, 2 channel, 16 bit)
DEBUG:alsa_1_0_0.alsaaudioengine:output stream closed on device 'front-card-alsa'

my config is as follows: Change input_device and output_device with yours.

audio_engine: 'alsa'
input_device: 'front-card-u0x46d0x825'
output_device: 'front-card-alsa'   
audio:
   input_samplerate: '16000'
   input_samplewidth: '16'
   input_channels: '1'
   input_chunksize: '1024'
   output_chunksize: '320'
   output_padding: 'no'

Also try this change: line 103 in jasper-client/plugins/audioengine/alsa-ae/alsaaudioengine.py

Change-

        stream = alsaaudio.PCM(type=pcm_type,
                               mode=alsaaudio.PCM_NORMAL,
                               device='default')

To-

        stream = alsaaudio.PCM(type=pcm_type,
                               mode=alsaaudio.PCM_NORMAL,
                               device=self.name)
bruxi commented 7 years ago

Thanks a lot, that leaded me to a solution. With your settings my Jasper sounded like Micky Mouse and the mic didn't recognize anything, but with these settings it works for me now:

output_device: convert

with convert configured like this in ~/.asoundrc:

pcm.convert {
         type plug;
         slave {
               pcm default;
               rate 48000;
         }
}

and the following settings in profile.yml:

audio:
   input_samplerate: '8000'
   input_samplewidth: '16'
   input_channels: '1'
   input_chunksize: '1024'
   output_chunksize: '1024'
   output_padding: 'no'
G10DRAS commented 7 years ago

You are lucky you got Micky Mouse. What USB Soundcard or Mic you are using ? and what are the sample rates it support ?

And by using below setting you are upsampling input audio in Jasper , which is not good.

audio:
   input_samplerate: '8000'

Most of the STT needs input_samplerate set to 16000.

bruxi commented 7 years ago

I'm still using the internal card as you said that it's working fine. Output is fine now with the settings above. My mic is a Kinobo Mini Akiro which show up in lsusb like this: Bus 001 Device 017: ID 0c76:160a JMTek, LLC.

My imagination was that with a sample rate of 8000 speech recognition is better than with 16000.

bruxi commented 7 years ago

I followed your hint and set the sample rate of the mic back to 16000. But then I get

INFO:jasper.mic:Waiting for keyword 'Hertha'...
INFO:urllib3.connectionpool:Starting new HTTPS connection (1): www.google.com
WARNING:google_1_0_0.google:Empty response: Nothing has been transcribed.
WARNING:google_1_0_0.google:Empty response: Nothing has been transcribed.
WARNING:google_1_0_0.google:Empty response: Nothing has been transcribed.
WARNING:google_1_0_0.google:Empty response: Nothing has been transcribed.
WARNING:google_1_0_0.google:Empty response: Nothing has been transcribed.
WARNING:google_1_0_0.google:Empty response: Nothing has been transcribed.
WARNING:google_1_0_0.google:Empty response: Nothing has been transcribed.
WARNING:google_1_0_0.google:Empty response: Nothing has been transcribed.

continously. Changing the value back to 8000 results in:

INFO:urllib3.connectionpool:Starting new HTTPS connection (1): translate.google.com
INFO:jasper.mic:Waiting for keyword 'Hertha'...
INFO:urllib3.connectionpool:Starting new HTTPS connection (1): www.google.com
INFO:google_1_0_0.google:Transcribed: (u'HERTHA', u'HERTA', u'H\xc4RTER', u'JATTA', u'HERTER')
INFO:jasper.mic:Keyword Hertha has been uttered
G10DRAS commented 7 years ago

seems you are using Google STT for both active and passive listening. no issue then, happy jaspering.