Beispiel #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()
Beispiel #2
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()
Beispiel #3
0
class MyListener(SttWatsonAbstractListener):
    def __init__(self):
        pass

    """
    This give hypothesis from watson when your sentence is finished
    """

    def listenHypothesis(self, hypothesis):
        print("Hypothesis: {0}".format(hypothesis))

    """
    This give the json received from watson
    """

    def listenPayload(self, payload):
        print(u"Text message received: {0}".format(payload))

    """
    This give hypothesis from watson when your sentence is not finished
    """

    def listenInterimHypothesis(self, interimHypothesis):
        print("Interim hypothesis: {0}".format(interimHypothesis))


myListener = MyListener()
sttWatson = SttWatson('b189f5ce-1f20-4dd9-a97d-0b49b9bd2318', 'cUHVuqPzAOvP')
sttWatson.addListener(myListener)
sttWatson.run()