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 = env.get_endpoint() + "/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)
Exemplo n.º 2
0
try:
    language_id = "&language_customization_id=" + os.environ['LANGUAGE_ID']
    print(" - custom language model (id: %s)" % os.environ['LANGUAGE_ID'])
except:
    language_id = ""
    print(" - base language model")

try:
    acoustic_id = "&acoustic_customization_id=" + os.environ['ACOUSTIC_ID']
    print(" - custom acoustic model (id: %s)" % os.environ['ACOUSTIC_ID'])
except:
    acoustic_id = ""
    print(" - base acoustic model")

audio_file = env.get_arg("audio file to transcribe")
uri = env.get_endpoint(
) + "/v1/recognize?model=en-US_NarrowbandModel" + language_id + acoustic_id
with open(audio_file, 'rb') as f:
    r = requests.post(uri,
                      auth=(env.get_username(), env.get_password()),
                      verify=False,
                      headers=headers,
                      data=f)

output_file = open(audio_file.replace('.wav', '') + '.transcript', 'w')
transcript = ""
print(r.json())
for result in r.json()['results']:
    for alternative in result['alternatives']:
        transcript += alternative['transcript']

print("Transcription: ")
# -*- 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)

##########################################################################
# Get list of custom lanugage models
##########################################################################

print("\nGetting custom language models...")

headers = {'Content-Type': "application/json"}
uri = env.get_endpoint() + "/v1/customizations"
r = requests.get(uri,
                 auth=(env.get_username(), env.get_password()),
                 verify=False,
                 headers=headers)

print("Get models returns: ", r.status_code)
print(r.text)

sys.exit(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)

##########################################################################
# Initiates the training of a custom acoustic model with new audio resources
# using a language model as the base
# A status of available means that the custom model is trained and ready to use.
##########################################################################

print("\nTrain custom acoustic model...")

headers = {'Content-Type' : "application/json"}
uri = env.get_endpoint() + "/v1/acoustic_customizations/"+env.get_acoustic_id()+"/train?custom_language_model_id="+env.get_language_id()
r = requests.post(uri, auth=(env.get_username(),env.get_password()), verify=False, headers=headers)

print("Train acoustic model returns: ", r.status_code)

sys.exit(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)

##########################################################################
# Delete a custom acoustic model
##########################################################################

print("\nDeleting custom acoustic models...")

headers = {'Content-Type': "application/json"}
uri = env.get_endpoint(
) + "/v1/acoustic_customizations/" + env.get_acoustic_id()
resp = requests.delete(uri,
                       auth=(env.get_username(), env.get_password()),
                       verify=False,
                       headers=headers)

print("Delete acoustic models returns: ", resp.status_code)
if resp.status_code != 200:
    print("Failed to delete acoustic model")
    print(resp.text)
    sys.exit(-1)

sys.exit(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)

##########################################################################
# Get list of all custom models
##########################################################################

print("\nGetting all models...")

headers = {'Content-Type': "application/json"}
uri = env.get_endpoint() + "/v1/models"
r = requests.get(uri,
                 auth=(env.get_username(), env.get_password()),
                 verify=False,
                 headers=headers)

print("Get all models returns: ", r.status_code)
print(r.text)

sys.exit(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)

##########################################################################
# Delete a corpus file from a custom language model
##########################################################################

corpusName = env.get_arg("corpus filename")

print("\nDeleting corpus ...")

headers = {'Content-Type' : "application/json"}
uri = env.get_endpoint() + "/v1/customizations/"+env.get_language_id()+"/corpora/"+corpusName
r = requests.delete(uri, auth=(env.get_username(),env.get_password()), verify=False, headers=headers)

print("Delete corpus returns: ", r.status_code)
if r.status_code != 200:
   print("Failed to get corpus")
   print(r.text)
   sys.exit(-1)
else:
   sys.exit(0)