Ejemplo n.º 1
0
# -*- coding: utf-8 -*-
import requests
import json
import codecs
import sys, time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import env

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

##########################################################################
# Resets a custom language model by removing all corpora, grammars, and words from
# the model. Resetting a custom language model initializes the model to its state
# when it was first created. Metadata such as the name and language of the model
# are preserved, but the model's words resource is removed and must be re-created.
# You must use credentials for the instance of the service that owns a model to reset it.
##########################################################################

print("\nResetting custom language model...")

headers = {'Content-Type' : "application/json"}
uri = "https://stream.watsonplatform.net/speech-to-text/api/v1/customizations/"+env.get_language_id()+"/reset"
r = requests.post(uri, auth=(env.get_username(),env.get_password()), verify=False, headers=headers)

print("Reset model returns: ", r.status_code)
print(r.text)

sys.exit(0)
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import env

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

##########################################################################
# Create a custom language model
##########################################################################

model_name = env.get_arg("language model name")
print "\nCreate a new language custom model: " + model_name

headers = {'Content-Type': "application/json"}
data = {
    "name": model_name,
    "base_model_name": "en-US_NarrowbandModel",
    "description": "My narrowband language model"
}
uri = "https://stream.watsonplatform.net/speech-to-text/api/v1/customizations/"
jsonObject = json.dumps(data).encode('utf-8')
r = requests.post(uri,
                  auth=(env.get_username(), env.get_password()),
                  verify=False,
                  headers=headers,
                  data=jsonObject)

print "Create model returns: ", r.status_code
print r.text

sys.exit(0)
Ejemplo n.º 3
0
import requests
import json
import codecs
import sys, time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import env

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

##########################################################################
# Create a new custom acoustic model
##########################################################################

model_name = env.get_arg("acoustic model name")
print "\nCreate a new acoustic custom model: "+model_name

headers = {'Content-Type' : "application/json"}
data = {"name" : model_name, "base_model_name" : "en-US_NarrowbandModel", "description" : "My narrowband acoustic model"}
uri = "https://stream.watsonplatform.net/speech-to-text/api/v1/acoustic_customizations"
jsonObject = json.dumps(data).encode('utf-8')
resp = requests.post(uri, auth=(env.get_username(),env.get_password()), verify=False, headers=headers, data=jsonObject)

print "Create acoustic models returns: ", resp.status_code
if resp.status_code != 201:
   print "Failed to create acoustic model"
   print resp.text
   sys.exit(-1)
else:
   print resp.text
   sys.exit(0)