예제 #1
0
def main():
    home = os.path.expanduser("~")
    defaultConfigFile = home + '/.config-stt-watson.yml'
    parser = argparse.ArgumentParser(
        description=
        'Speech to text using watson in python with websocket and record from microphone'
    )

    parser.add_argument('-f',
                        action='store',
                        dest='configFile',
                        default=defaultConfigFile,
                        help='config file',
                        required=False)
    args = parser.parse_args()
    if not os.path.isfile(args.configFile):
        print "Config file '" + args.configFile + "' doesn't exist."
        print "Creating it ..."
        data = pkgutil.get_data('config', 'config.sample.yml')
        Config.Instance().loadConfigFromResource(data)
        watsonConfig = Config.Instance().getWatsonConfig()
        user = raw_input("Watson user: "******"Watson password: "******"user"] = user
        watsonConfig["password"] = password
        f = open(args.configFile, 'w')
        f.write(yaml.dump(Config.Instance().getConfig()))
        f.close()

    Config.Instance().setConfigFile(args.configFile)
    sttWatsonLogListener = SttWatsonLogListener()
    watsonConfig = Config.Instance().getWatsonConfig()
    sttWatson = SttWatson(watsonConfig["user"], watsonConfig["password"])
    sttWatson.addListener(sttWatsonLogListener)
    sttWatson.run()
예제 #2
0
 def __init__(self, stopper):
     threading.Thread.__init__(self)
     self.p = pyaudio.PyAudio()
     self.writer = None
     self.stopper = stopper
     self.channels = Config.Instance().getChannels()
     self.rate = Config.Instance().getAudioRate()
     self.chunk = Config.Instance().getAudioChunk()
     self.pauseRecord = False
예제 #3
0
 def __init__(self,
              user,
              password,
              model=None,
              rate=None,
              chunk=None,
              channels=None):
     if not Config.Instance().getConfig():
         Config.Instance().setConfig(self.default_config)
     watsonConfig = Config.Instance().getWatsonConfig()
     watsonConfig["user"] = user
     watsonConfig["password"] = password
     if model is not None:
         watsonConfig["model"] = model
     if chunk is not None:
         Config.Instance().setAudioChunk(chunk)
     if rate is not None:
         Config.Instance().setAudioRate(rate)
     if channels is not None:
         Config.Instance().setChannels(channels)
     Config.Instance().setWatsonConfig(watsonConfig)
     self.listeners = []
     self.stopper = threading.Event()
     self.record = Record(self.stopper)
     self.workers = [self.record]
     self.watsonClient = Client()
     self.handler = SignalHandler(self.stopper, self.workers)
     signal.signal(signal.SIGINT, self.handler)
 def __init__(self, factory, audioFd, summary, contentType):
     self.listeners = []
     self.audioFd = audioFd
     self.factory = factory
     self.summary = summary
     self.contentType = contentType
     self.packetRate = 20
     self.listeningMessages = 0
     self.timeFirstInterim = -1
     self.bytesSent = 0
     self.chunkSize = Config.Instance().getAudioChunk()  # in bytes
     super(self.__class__, self).__init__()
     print "contentType: " + str(self.contentType)
예제 #5
0
 def __init__(self):
     self.listeners = []
     self.configData = Config.Instance().getWatsonConfig()