Esempio n. 1
0
def main():
    import time
    import datetime
    from voice_engine.source import Source
    from voice_engine.channel_picker import ChannelPicker
    from voice_engine.file_sink import FileSink

    src = Source(channels=2, rate=48000, frames_size=48000)
    chx = ChannelPicker(channels=src.channels, pick=0)
    thd = THD(1000, src.rate)

    filename = '2.94dB1KHz.' + datetime.datetime.now().strftime("%Y%m%d.%H:%M:%S") + '.wav'

    sink = FileSink(filename, channels=src.channels, rate=src.rate)

    src.link(sink)
    src.pipeline(chx, thd)

    src.pipeline_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()
Esempio n. 2
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='alexa')
    alexa = Alexa()

    alexa.state_listener.on_listening = pixel_ring.listen
    alexa.state_listener.on_thinking = pixel_ring.think
    alexa.state_listener.on_speaking = pixel_ring.speak
    alexa.state_listener.on_finished = pixel_ring.off

    src.pipeline(ns, kws, alexa)

    def on_detected(keyword):
        logging.info('detected {}'.format(keyword))
        alexa.listen()

    kws.set_callback(on_detected)

    is_quit = []
    def signal_handler(signal, frame):
        is_quit.append(True)
        print('Quit')
    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break
    src.pipeline_stop()
Esempio n. 3
0
File: ns_kws.py Progetto: wbaiyu/avs
def main():
    src = Source(rate=16000, channels=2)
    ch1 = ChannelPicker(channels=2, pick=1)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='snowboy', sensitivity=0.6, verbose=True)

    src.pipeline(ch1, ns, kws)

    def on_detected(keyword):
        print('detected {}'.format(keyword))

    kws.set_callback(on_detected)

    src.pipeline_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()

    # wait a second to allow other threads to exit
    time.sleep(1)
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ec = EC(channels=src.channels, capture=0, playback=7)
    ns = NS(rate=src.rate, channels=1)
    kws = KWS()

    # data flow between elements
    # ---------------------------
    # src -> ec -> ns -> kws
    src.pipeline(ec, ns, kws)

    def on_detected(keyword):
        led.toggle()
        print('detected {}'.format(keyword))

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()

    # wait a second to allow other threads to exit
    time.sleep(1)
    led.off()
Esempio n. 5
0
def main():
    import time
    from voice_engine.source import Source
    from voice_engine.kws import KWS

    src = Source(rate=16000, channels=2, frames_size=1600)
    route = Route(channels=src.channels)
    kws = []

    def gen(channel):
        def on_detected(keyword):
            print('detected at channel {}'.format(channel))

        return on_detected

    for ch in range(src.channels):
        k = KWS(sensitivity=0.5)
        k.set_callback(gen(ch))
        kws.append(k)

    src.pipeline(route, kws)

    src.pipeline_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()
Esempio n. 6
0
File: bing.py Progetto: wbaiyu/avs
def main():
    import time
    from voice_engine.channel_picker import ChannelPicker
    from voice_engine.kws import KWS
    from voice_engine.source import Source

    src = Source(channels=2)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='snowboy', sensitivity=0.7)
    bing = Bing(BING_KEY)

    src.pipeline(ch0, kws, bing)

    def on_detected(keyword):
        print('detected {}'.format(keyword))
        bing.listen()

    kws.set_callback(on_detected)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
Esempio n. 7
0
def main():
    logging.basicConfig(level=logging.DEBUG)

    src = Source(rate=16000)
    ns = NS(rate=16000, channels=1)
    kws = KWS(model='alexa')
    alexa = Alexa()

    src.pipeline(ns, kws, alexa)

    def on_detected(keyword):
        logging.info('detected {}'.format(keyword))
        alexa.listen()

    kws.set_callback(on_detected)

    src.pipeline_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()
Esempio n. 8
0
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='snowboy', sensitivity=0.5)
    doa = DOA(rate=src.rate, chunks=20)

    src.pipeline(ch0, kws)

    src.link(doa)

    def on_detected(keyword):
        direction = doa.get_direction()
        print('detected {} at direction {}'.format(keyword, direction))
        pixel_ring.wakeup(direction)
        time.sleep(2)
        pixel_ring.off()

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
Esempio n. 9
0
def main():
    src = Source(rate=16000, channels=6, device_name='hw:1')
    route = Route(channels=src.channels)

    def get_kws_callback(channel):
        def on_detected(keyword):
            print('detected @ {}'.format(channel))

        return on_detected

    kws = []
    for channel in range(2):
        k = KWS(model='snowboy', sensitivity=0.6)
        k.on_detected = get_kws_callback(channel)

        kws.append(k)

    sink = FileSink('c6.wav', rate=src.rate, channels=src.channels)

    src.pipeline(route, kws)
    src.link(sink)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
Esempio n. 10
0
def main():
    src = Source(rate=16000, channels=8)
    ch1 = ChannelPicker(channels=8, pick=1)
    kws = KWS()

    filename = '4.kws.' + datetime.datetime.now().strftime(
        "%Y%m%d.%H:%M:%S") + '.wav'

    sink = FileSink(filename, channels=src.channels, rate=src.rate)

    src.link(sink)
    src.pipeline(ch1, kws)

    def on_detected(keyword):
        print('detected {}'.format(keyword))

    kws.set_callback(on_detected)

    src.recursive_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.recursive_stop()
Esempio n. 11
0
def main():
    import time
    from voice_engine.source import Source

    src = Source(rate=48000, channels=2, frames_size=4800)
    dbfs = DBFS(channels=src.channels)
    src.pipeline(dbfs)

    src.pipeline_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()
Esempio n. 12
0
def main():
    from voice_engine.source import Source

    src = Source(rate=16000, channels=1)
    assistant = Mirror()

    src.pipeline(assistant)
    src.pipeline_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()
Esempio n. 13
0
def main():
    src = Source(rate=16000, frames_size=160, channels=2)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    ns = NS(rate=src.rate, channels=1)
    kws = KWS()
    doa = DOA(rate=16000, chunks=50)
    alexa = Alexa()

    alexa.state_listener.on_listening = pixel_ring.listen
    alexa.state_listener.on_thinking = pixel_ring.think
    alexa.state_listener.on_speaking = pixel_ring.speak
    alexa.state_listener.on_finished = pixel_ring.off

    # data flow between elements
    # ---------------------------
    # src -> ns -> kws -> alexa
    #    \
    #    doa
    src.pipeline(ch0, ns, kws, alexa)

    src.link(doa)

    def on_detected(keyword):
        direction = doa.get_direction()
        print('detected {} at direction {}'.format(keyword, direction))
        alexa.listen()
        pixel_ring.wakeup(direction)

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
    pixel_ring.off()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 14
0
def main():
    import time
    from voice_engine.source import Source

    src = Source(rate=16000, channels=2, frames_size=1600)
    ec = EC(channels=src.channels, capture=0, playback=1)

    src.pipeline(ec)
    src.pipeline_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()
Esempio n. 15
0
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ec = EC(channels=src.channels, capture=0, playback=7)
    ns = NS(rate=src.rate, channels=1)
    kws = KWS()
    doa = DOA(rate=16000, chunks=20)
    alexa = Alexa()

    alexa.state_listener.on_listening = pixel_ring.listen
    alexa.state_listener.on_thinking = pixel_ring.think
    alexa.state_listener.on_speaking = pixel_ring.speak
    alexa.state_listener.on_finished = pixel_ring.off

    src.pipeline(ec, ns, kws, alexa)

    src.link(doa)

    def on_detected(keyword):
        direction = doa.get_direction()
        print('detected {} at direction {}'.format(keyword, direction))
        alexa.listen()
        pixel_ring.wakeup(direction)

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
    pixel_ring.off()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 16
0
def main():
    src = Source(rate=16000, channels=1, device_name="default")
    kws = KWS(model='computer', sensitivity=0.6, verbose=True)

    src.pipeline(kws)

    def on_detected(keyword):
        print('\ndetected {}'.format(keyword))

    kws.set_callback(on_detected)

    src.pipeline_start()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ec = EC(channels=src.channels, capture=0, playback=7)
    ns = NS(rate=src.rate, channels=1)
    kws = KWS()
    doa = DOA(rate=16000, chunks=20)

    # data flow between elements
    # ---------------------------
    # src -> ec -> ns -> kws
    #    \
    #    doa
    src.pipeline(ec, ns, kws)
    src.link(doa)

    def on_detected(keyword):
        direction = doa.get_direction()
        print('detected {} at direction {}'.format(keyword, direction))
        pixel_ring.wakeup(direction)

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
    pixel_ring.off()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 18
0
def main():
    src = Source(rate=16000, channels=8, frames_size=1600)
    ec = EC(channels=src.channels, capture=0, playback=6)
    kws = KWS(sensitivity=0.7)

    def on_detected(keyword):
        global count
        count += 1
        print('detected {}'.format(keyword))

    kws.on_detected = on_detected

    src.pipeline(ec, kws)

    src.pipeline_start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    print('total = {}'.format(count))
    src.pipeline_stop()
Esempio n. 19
0
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='alexa', sensitivity=0.8)
    doa = DOA(rate=src.rate, chunks=20)
    alexa = Alexa()

    alexa.state_listener.on_listening = pixel_ring.listen
    alexa.state_listener.on_thinking = pixel_ring.think
    alexa.state_listener.on_speaking = pixel_ring.speak
    alexa.state_listener.on_finished = pixel_ring.off

    src.pipeline(ch0, kws, alexa)

    src.link(doa)

    def on_detected(keyword):
        direction = doa.get_direction()
        print('detected {} at direction {}'.format(keyword, direction))
        alexa.listen()
        pixel_ring.wakeup(direction)

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ec = EC(channels=src.channels, capture=0, playback=7)
    # ns = NS(rate=src.rate, channels=1)
    kws = KWS(model='alexa')
    alexa = Alexa()

    alexa.state_listener.on_listening = led.on
    alexa.state_listener.on_finished = led.off

    #src.pipeline(ec, ns, kws, alexa)
    src.pipeline(ec, kws, alexa)

    def on_detected(keyword):
        led.on()
        print('detected {}'.format(keyword))
        alexa.listen()

    kws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()
    led.off()

    # wait a second to allow other threads to exit
    time.sleep(1)
Esempio n. 21
0
def main():
    from voice_engine.source import Source
    from voice_engine.ns import NS
    from bf import BF

    src = Source(rate=16000, channels=8)
    bf = BF()
    ns = NS()
    assistant = Mirror()

    src.pipeline(bf, ns, assistant)
    ns.link(alexa)

    src.pipeline_start()

    led.off()

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    src.pipeline_stop()
Esempio n. 22
0
if __name__ == "__main__":

    quit_event = threading.Event()

    client_secret = 'INSERT YOUR CLIENT SECRET'
    auth_client = AzureAuthClient(client_secret)

    # src = Source(rate=16000, frames_size=160)

    src = Source(channels=8, rate=16000, frames_size=160)
    doa = DOA(channels=8)

    audio_buffer = AudioBuffer()

    src.pipeline(doa, audio_buffer)

    player = Player()

    # Translate from this language. The language must match the source audio.
    # Supported languages are given by the 'speech' scope of the supported languages API.
    translate_from = 'en-US'
    # Translate to this language.
    # Supported languages are given by the 'text' scope of the supported languages API.
    translate_to = 'zh-HANS'
    # Features requested by the client.
    features = "Partial,TextToSpeech"

    # Transcription results will be saved into a new folder in the current directory
    output_folder = os.path.join(os.getcwd(), uuid.uuid4().hex)
Esempio n. 23
0
def main():
    src = Source(rate=48000,
                 channels=4,
                 device_name='voicen',
                 bits_per_sample=32)
    decoder = Decoder(channels=src.channels, select=0, bits_per_sample=32)

    def on_data(data):
        print([c for c in data])
        ssid_length = data[0]
        ssid = data[1:ssid_length + 1].tostring().decode('utf-8')
        password_length = data[ssid_length + 1]
        password = data[ssid_length + 2:ssid_length + password_length +
                        2].tostring().decode('utf-8')
        # print(u'SSID: {}\nPassword: {}'.format(ssid, password))

        cmd = 'mosquitto_pub -t /voicen/hey_wifi -m 2'
        os.system(cmd)

        if os.system('which nmcli >/dev/null') != 0:
            print('nmcli is not found')
            return

        cmd = 'nmcli device wifi rescan'
        os.system(cmd)

        cmd = u'nmcli connection delete "{}"'.format(ssid)
        os.system(cmd)

        cmd = u'nmcli device wifi connect "{}" password "{}"'.format(
            ssid, password)
        if os.system(cmd) != 0:
            print('Failed to connect the Wi-Fi network')
            return

        print('Wi-Fi is connected')
        ip_info = get_ip_info()
        if not ip_info:
            print('Not find any IP address')
            return

        print(ip_info)
        decoder.done = True

        cmd = 'mosquitto_pub -t /voicen/hey_wifi -m 3'
        os.system(cmd)

        channel = int((data[-1] << 8) + data[-2])
        payload = json.dumps({'id': channel, 'data': ip_info.decode()})
        message = encrypt(channel, data, payload.encode())
        if os.system('which mosquitto_pub >/dev/null') != 0:
            print('mosquitto_pub is not found')

        cmd = 'mosquitto_pub -h q.voicen.io -u mqtt -P mqtt -q 1 -t "/voicen/hey_wifi/{}" -m "{}"'.format(
            channel, message)
        print(cmd)
        for _ in range(3):
            if os.system(cmd) == 0:
                break
        else:
            print('Failed to send message to the web page')

        print('Done')
        cmd = 'mosquitto_pub -t /voicen/hey_wifi -m 4'
        os.system(cmd)

    decoder.on_data = on_data

    src.pipeline(decoder)
    src.pipeline_start()

    while not decoder.done:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            print('exit')
            break

    src.pipeline_stop()
Esempio n. 24
0
def CtrlC(signum, frame):
    os.kill(os.getpid(), signal.SIGKILL)


'''
 main  start ...
'''
if __name__ == "__main__":
    try:
        src = Source(channels=8)
        ch0 = ChannelPicker(channels=src.channels, pick=0)
        ns = NS()

        bing = Bing(BING_KEY)

        src.pipeline(ch0, ns, bing)

        bing_api_call()

        signal.signal(signal.SIGINT, CtrlC)
        signal.signal(signal.SIGTERM, CtrlC)

        thread_key = threading.Thread(target=key_hander, args=(1, ))
        thread_play = threading.Thread(target=pre_play, args=(1, ))

        thread_key.setDaemon(True)
        thread_play.setDaemon(True)

        thread_key.start()
        thread_play.start()
Esempio n. 25
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setWindowTitle('Audio Measuring Experiment')
        self.resize(800, 500)
        self.cwidget = QWidget()
        self.setCentralWidget(self.cwidget)
        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.cwidget.setLayout(layout)
        self.plotwidget = pg.PlotWidget()
        layout.addWidget(self.plotwidget)

        self.plotwidget.setTitle(title="press 'space' to freeze/resume")

        self.plot = self.plotwidget.plot()
        self.plot.setPen((0, 255, 0))

        self.ff = pg.TextItem('fundamental frequency', anchor=(0, 0))
        self.plotwidget.addItem(self.ff)
        self.ff.setPos(100, 0)

        self.arrow = pg.ArrowItem(pos=(100, 0), angle=-45)
        self.plotwidget.addItem(self.arrow)

        plotitem = self.plotwidget.getPlotItem()
        # plotitem.hideAxis('left')
        # plotitem.hideAxis('bottom')

        self.freeze = False
        self.timer = pg.QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(50)

        self.src = Source(rate=48000, frames_size=4800)
        chx = ChannelPicker(channels=self.src.channels, pick=0)
        thd = THD(1000, self.src.rate)

        filename = '2.94dB1KHz.' + datetime.datetime.now().strftime(
            "%Y%m%d.%H:%M:%S") + '.wav'

        sink = FileSink(filename,
                        channels=self.src.channels,
                        rate=self.src.rate)

        def on_data(d):
            global data

            data = d

        thd.on_data = on_data

        self.src.link(sink)
        self.src.pipeline(thd)

        self.src.pipeline_start()

    def update(self):
        global data

        if not self.freeze and data is not None:
            self.plot.setData(data)
            self.arrow.setPos(100, data[100])
            self.ff.setPos(100, 0)
            self.ff.setText(str(data[100]))

    def keyPressEvent(self, event):
        key = event.key()
        if key == Qt.Key_Space:
            self.freeze = not self.freeze
        elif key == Qt.Key_Escape:
            self.plotwidget.enableAutoRange()

        return True

    def closeEvent(self, event):
        self.src.pipeline_start()

        event.accept()
Esempio n. 26
0
import time
import signal
from voice_engine.source import Source
from voice_engine.kws import KWS
from alexa import Alexa
import logging

logging.basicConfig(level=logging.WARNING)

src = Source(rate=16000)
kws = KWS(model='alexa', sensitivity=0.5)
alexa = Alexa()

src.pipeline(kws, alexa)


def on_detected(keyword):
    print('detected {}'.format(keyword))
    alexa.listen()


kws.set_callback(on_detected)

is_quit = []


def signal_handler(signal, frame):
    print('Quit')
    is_quit.append(True)

def main():
    src = Source(rate=16000, frames_size=320, channels=8)
    ch0 = ChannelPicker(channels=src.channels, pick=0)
    kws = KWS(model='alexa', sensitivity=0.8)
    pws = KWS(model='/usr/share/respeaker/snowboy/resources/nivi.pmdl')

    def pwstest():
        print('calling Personal function')
        exit()

    doa = DOA(rate=src.rate, chunks=20)
    alexa = Alexa()
    alexa.state_listener.on_listening = pixel_ring.listen
    alexa.state_listener.on_thinking = pixel_ring.think
    alexa.state_listener.on_speaking = pixel_ring.speak
    alexa.state_listener.on_finished = pixel_ring.off

    src.pipeline(ch0, kws, alexa)

    src.pipeline(ch0, pws, doa)

    src.link(doa)

    def on_detected(keyword):
        print('ALEXA Testing fuction')
        direction = doa.get_direction()
        print('detected {} at direction {}'.format(keyword, direction))
        alexa.listen()
        pixel_ring.wakeup(direction)
        print('afteralexa')

    kws.on_detected = on_detected
    #pws.on_detected = on_detected
    print('afterkws before pws')

    #is_quit = []

    def on_detected(keyword):
        direction = doa.get_direction()
        print('PWS Testing')
        print('detected {} at direction {}'.format(keyword, direction))
        pwstest()
        #alexa.listen()
        pixel_ring.wakeup(direction)
        print('Personal function working')

    pws.on_detected = on_detected

    is_quit = []

    def signal_handler(sig, frame):
        is_quit.append(True)
        print('quit')

    signal.signal(signal.SIGINT, signal_handler)

    src.pipeline_start()
    while not is_quit:
        time.sleep(1)

    src.pipeline_stop()