错误processRemote类型与Pepper上的ALAudioDevice不匹配

时间:2018-02-23 15:07:17

标签: python nao-robot pepper choregraphe

我想录制Pepper麦克风的声音并将其传输到服务器。 我按照the naoqi documentation上的代码进行了调整,并将其修改为 Choregraphe python框

当我启动程序时,我遇到以下错误:

[ERROR] ALAudioDeviceClient :threadReader:0 Error on processRemote, stopping thread:    AudioModule::processRemote  Type mismatch

这是我的代码:

import qi

class AudioModule(object):
    def __init__(self):
        super(AudioModule, self).__init__()
        self.moduleName = "AudioModule"
        try :
            self.ALAudioDevice = ALProxy("ALAudioDevice")
        except Exception, e:
            self.logger.error("Error when creating proxy on ALAudioDevice:")
            self.logger.error(e)

    def begin_stream(self):
        self.ALAudioDevice.setClientPreferences(self.moduleName, 16000, 3, 0)
        self.ALAudioDevice.subscribe(self.moduleName)

    def end_stream(self):
        self.ALAudioDevice.unsubscribe(self.moduleName)

    def processRemote( self, nbOfChannels, samplesByChannel, altimestamp, buffer ):
        nbOfChannels = nbOfChannels
        #mylogger = qi.Logger("data")
        #mylogger.info("It works ! " + nbOfChannels)

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self, False)
        self.audio = AudioModule()

    def onLoad(self):
        self.serviceId = self.session().registerService("AudioModule", self.audio)
        pass

    def onUnload(self):
        if self.serviceId != -1:
            self.session().unregisterService(self.serviceId)
            self.serviceId = -1
        pass

    def onInput_onStart(self):
        self.audio.begin_stream()

    def onInput_onStop(self):
        self.audio.end_stream()

processRemote函数的结构与示例相同,为什么会出现Type不匹配错误?

提前致谢!

1 个答案:

答案 0 :(得分:1)

经常"类型不匹配"或"转换"错误可能来自您获得naoqi模块的方式。在这里你可以得到#34; old" (naoqi v.1)方式:

self.ALAudioDevice = ALProxy("ALAudioDevice")

哪会产生转换错误。您可以尝试通过会话以新方式获取它:

self.ALAudioDevice = self.session().service("ALAudioDevice")