Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Revert "树莓派2代B+版本Centos7 Userland系统PulseAudio支持及内置声卡、音量配置 (#131)"

This reverts commit 8585c57.
  • Loading branch information...
wzpan committed Mar 13, 2018
1 parent 8585c57 commit 14b1514d4fa12572bac1844811c1a72963bc1a78
Showing with 10 additions and 135 deletions.
  1. +0 −2 .travis.yml
  2. +0 −86 client/mic.py
  3. +0 −5 client/requirements.txt
  4. +10 −36 client/stt.py
  5. +0 −6 demo_sound_card_conf.yml
@@ -19,7 +19,5 @@ install:
- "pip install flake8 --cache-dir $HOME/.pip-cache"
before_script:
- "flake8 --exclude=wxbot.py,snowboydetect.py dingdang.py client --show-source"
before_install:
- sudo apt-get install -y swig libpulse-dev libavahi-client-dev libavahi-common-dev libpulse-mainloop-glib0 libpulse0
script:
- "nosetests -s --exe -v --with-coverage --cover-erase"
@@ -13,7 +13,6 @@
from . import dingdangpath
from . import mute_alsa
from .app_utils import wechatUser
import pulsectl


class Mic:
@@ -51,90 +50,6 @@ def __init__(self, profile, speaker, passive_stt_engine,
asound.snd_lib_error_set_handler(mute_alsa.c_error_handler)
except OSError:
pass

if 'sound_card' in profile:
sound_card = {'input': "", 'output': "",
'input_volume': 0.5, 'output_volume': 0.5}
sound_card['input'] = profile['sound_card']['input']
sound_card['input_volume'] = profile['sound_card']['input_volume']
sound_card['output'] = profile['sound_card']['output']
sound_card['output_volume'] = \
profile['sound_card']['output_volume']
self._logger.info("Setting Sound Input Device : %s, Volume: %s",
sound_card['input'], sound_card['input_volume'])
self._logger.info(
"Setting Sound Output Device : %s Volume: %s",
sound_card['output'],
sound_card['output_volume'])
self._pulse = pulsectl.Pulse('my-dingdang-robot-audio-pulse')
card_list = self._pulse.card_list()
sink_list = self._pulse.sink_list()
source_list = self._pulse.source_list()
index_input = 0
index_output = 0

for k, v in enumerate(card_list):
self._logger.info("Loading Sound Card %s : %s", k, v)
for k, v in enumerate(source_list):
if sound_card['input'] == v.name:
index_input = k
self._logger.info(
"Loading Sound Input List" +
" %s <Current>: name:%s , description: %s ",
k,
v.name,
v.description)
else:
self._logger.info("Loading Sound Input List" +
" %s : name: %s , description: %s ",
k, v.name, v.description)

for k, v in enumerate(sink_list):
if sound_card['output'] == v.name:
index_output = k
self._logger.info(
"Loading Sound Output List" +
" %s <Current Config Set> : name:%s , " +
"description: %s ",
k,
v.name,
v.description)
else:
self._logger.info("Loading Sound Output List" +
" %s : name: %s , description: %s ",
k, v.name, v.description)

default_sink_name = self._pulse.server_info().default_sink_name
default_source_name = self._pulse.server_info().default_source_name
self._logger.info("User Default Sound Output Device : %s",
default_sink_name)
self._logger.info("User Default Sound Input Device : %s",
default_source_name)
self._pulse.default_set(sink_list[index_output])
self._pulse.default_set(source_list[index_input])
input_volume = source_list[index_input].volume
output_volume = sink_list[index_output].volume
input_volume.value_flat = sound_card['input_volume']
output_volume.value_flat = sound_card['output_volume']
self._pulse.volume_set(source_list[index_input], input_volume)
self._pulse.volume_set(sink_list[index_output], output_volume)
default_sink_name = self._pulse.server_info().default_sink_name
default_source_name = self._pulse.server_info().default_source_name
sink_list = self._pulse.sink_list()
source_list = self._pulse.source_list()
input_volume = source_list[index_input].volume
output_volume = sink_list[index_output].volume
self._logger.info(
"Robot Current Sound Input Device:" +
" %s ,Volume: %s",
default_source_name,
input_volume)
self._logger.info(
"Robot Current Sound Output Device:" +
" %s ,Volume: %s",
default_sink_name,
output_volume)

self._audio = pyaudio.PyAudio()
self._logger.info("Initialization of PyAudio completed.")
self.stop_passive = False
@@ -143,7 +58,6 @@ def __init__(self, profile, speaker, passive_stt_engine,

def __del__(self):
self._audio.terminate()
self._pulse.close()

def getScore(self, data):
rms = audioop.rms(data, 2)
@@ -8,11 +8,6 @@ requests==2.5.0

# Pocketsphinx STT engine
cmuclmtk==0.1.5
# Pocketsphinx Python bindings
pocketsphinx==0.1.3

# PulseAudio Controll Support
pulsectl==18.3.1

# Email plugin
python-dateutil==2.3
@@ -148,14 +148,8 @@ def __init__(self, vocabulary, hmm_dir="/usr/local/share/" +
"hmm_dir in your profile.",
hmm_dir, ', '.join(missing_hmm_files))

from pocketsphinx import DefaultConfig
ps_config = DefaultConfig()
ps_config.set_string('-hmm', hmm_dir)
ps_config.set_string('-logfn', self._logfile)
ps_config.set_string('-lm', vocabulary.decoder_kwargs['lm'])
ps_config.set_string('-dict', vocabulary.decoder_kwargs['dict'])

self._decoder = ps.Decoder(ps_config)
self._decoder = ps.Decoder(hmm=hmm_dir, logfn=self._logfile,
**vocabulary.decoder_kwargs)

def __del__(self):
os.remove(self._logfile)
@@ -195,23 +189,14 @@ def transcribe(self, fp):
self._decoder.process_raw(data, False, True)
self._decoder.end_utt()

result = []
transcribed = []
hyp = self._decoder.hyp()

result = self._decoder.get_hyp()
with open(self._logfile, 'r+') as f:
for line in f:
self._logger.debug(line.strip())
f.truncate()

if hyp and len(hyp.hypstr) > 1:
result = hyp.hypstr.split(' ')
transcribed = [result[0]]
self._logger.info('PocketSphinx 识别到了:%r', transcribed)
else:
transcribed = result = ['']
self._logger.info('PocketSphinx 未识别到关键字,识别结果:%r', transcribed)

transcribed = [result[0]]
self._logger.info('PocketSphinx 识别到了:%r', transcribed)
return transcribed

def transcribe_keyword(self, data):
@@ -229,17 +214,10 @@ def transcribe_keyword(self, data):
self._decoder.process_raw(data, False, True)
self._decoder.end_utt()

result = []
transcribed = []
hyp = self._decoder.hyp()
if hyp and len(hyp.hypstr) > 1:
result = hyp.hypstr.split(' ')
transcribed = [result[0]]
self._logger.info('PocketSphinx 识别到了:%r', transcribed)
else:
transcribed = result = ['']
self._logger.info('PocketSphinx 未识别到关键字,识别结果:%r', transcribed)
result = self._decoder.get_hyp()

transcribed = [result[0]]
self._logger.info('PocketSphinx 识别到了:%r', transcribed)
return transcribed

@classmethod
@@ -366,11 +344,7 @@ def transcribe(self, fp):
transcribed = []
if text:
transcribed.append(text.upper())
self._logger.info(u'百度语音识别到了: %s' % text)
else:
self._logger.info(u'百度语音识别错误: code: %s, msg: %s',
r.json()['err_no'], r.json()['err_msg'])

self._logger.info(u'百度语音识别到了: %s' % text)
return transcribed

@classmethod
@@ -851,7 +825,7 @@ def get_engine_by_slug(slug=None):
ValueError if no speaker implementation is supported on this platform
"""

if not slug or not isinstance(slug, str):
if not slug or type(slug) is not str:
raise TypeError("Invalid slug '%s'", slug)

selected_engines = filter(lambda engine: hasattr(engine, "SLUG") and

This file was deleted.

0 comments on commit 14b1514

Please sign in to comment.
You can’t perform that action at this time.