コード例 #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)

##########################################################################
# 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 = "https://stream.watsonplatform.net/speech-to-text/api/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)
コード例 #2
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 = "https://gateway-lon.watsonplatform.net/speech-to-text/api/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)
コード例 #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)

##########################################################################
# List the audio sources for an acoustic model
##########################################################################

print "\nGetting audio sources ..."

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

print "Get audio sources returns: ", r.status_code
if r.status_code != 200:
    print "Failed to get corpus"
    sys.exit(-1)
else:
    print r.text
    sys.exit(0)
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
import codecs
import sys, time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import env

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

##########################################################################
# Delete an audio source file from the acoustic model
##########################################################################

print("\nDeleting audio source ...")

audio_name = env.get_arg("name of audio source")
headers = {'Content-Type': "application/json"}
uri = env.get_endpoint(
) + "/v1/acoustic_customizations/" + env.get_acoustic_id(
) + "/audio/" + audio_name
r = requests.delete(uri,
                    auth=(env.get_username(), env.get_password()),
                    verify=False,
                    headers=headers)

print("Delete audio source returns: ", r.status_code)
if r.status_code != 200:
    print("Failed to delete audio source")
    print(r.text)
    sys.exit(-1)
else:
    sys.exit(0)
コード例 #7
0
import env

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

headers = {'Content-Type': "audio/wav"}

##########################################################################
# Transcribe an audio file using a custom language and acoustic model
# Need to specify in the API call:
# - the base model
# - the language_customization_id
# - the acoustic_customization_id
##########################################################################

print "\nTranscribe an audio using a custom language custom model..."

audio_file = env.get_arg("audio file to transcribe")
uri = "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel&language_customization_id=" + env.get_language_id(
) + "&acoustic_customization_id=" + env.get_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)

print "Transcribe returns: ", r.status_code
print r.text

sys.exit(0)