Language Model Action Set

End-to-End Speech to Text Using a Step-by-Step Approach

This example is not available for the CAS programming language.

End-to-End Speech to Text Using a Step-by-Step Approach

This example is not available for the Lua programming language.

End-to-End Speech to Text Using a Step-by-Step Approach

This section contains Python code. For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.

The following code shows how you can use a step-by-step approach to end-to-end speech recognition in CAS:

 # step 1: import the SAS Scripting Wrapper for Analytics Transfer library
 from swat import *

 # step 2: start a CAS session
 s = CAS(host, port)

 # step 3: load CAS action sets
 s.loadactionset("audio")
 s.loadactionset("deepLearn")
 s.loadactionset("langModel")

 # step 4: load audio data for test set
 s.audio.loadaudio(path   = "test.listing",
                 casOut = {"name": "test_audio", "replace": True},
                 )

 # step 5: extract MFCC features from audio files for test set
 # Note: Values of the "frameExtractionOptions", "melBanksOptions", "mfccOptions"
 #       and "featureScalingMethod" parameters must be the SAME as those used to
 #       train the RNN acoustic model.
 s.audio.computefeatures(
     table                  = "test_audio",
     casOut                 = {"name": "test_dlscore_input", "replace": True},
     audioColumn            = "_audio_",
     copyvars               = ["_path_"],
     frameExtractionOptions = {"frameShift": 10, "frameLength": 25, "dither": 0.0},
     melBanksOptions        = {"nBins": 40},
     mfccOptions            = {"nCeps": 40},
     featureScalingMethod   = "STANDARDIZATION",
     nOutputFrames          = 1500,
 )

 # step 6: import the pretrained RNN acoustic model if it's not in-memory
 s.table.loadtable(path = "acoustic_model.sashdat",
                 casOut = {"name": "asr", "replace": True},
                 )
 s.table.loadtable(path = "acoustic_model_weights.sashdat",
                 casOut = {"name": "pretrained_weights", "replace": True},
                 )
 s.table.loadtable(path = "acoustic_model_weights_attr.sashdat",
                 casOut = {"name": "pretrained_weights_attr", "replace": True},
                 )
 s.table.attribute(task = "ADD",
                 name = "pretrained_weights",
                 attrtable = "pretrained_weights_attr"
                 )

 # step 7: use pretrained RNN model to score acoustic features of test set
 s.dlScore(table          = "test_dlscore_input",
         model          = "asr",
         initweights    = "pretrained_weights",
         layerImageType = 'WIDE',
         copyvars       = ['_path_'],
         casOut         = {"name": "test_rnn_scores", "replace": True},
         )

 # step 8: import an n-gram language model
 s.langModel.lmImport(table  = "language_model.sashdat",
                     casOut = "language_model"
                     )

 # step 9: decode RNN scores
 s.langModel.lmDecode(table          = "test_rnn_scores",
                     langModelTable = "language_model",
                     blankLabel     = " ",
                     spaceLabel     = "&",
                     copyvars       = ['_path_'],
                     casOut         = "test_results"
                     )

 # step 10: save the results
 s.save(table = "test_results",
     name  = "test_results.csv",
     replace = True
     )

End-to-End Speech to Text Using a Step-by-Step Approach

This example is not available for the R programming language.

Last updated: August 04, 2026