SAP Fiori Client Guide

Voice Recording Samples

Hybrid SDK (Kapsel) applications for Android, iOS and Windows platforms.

Capture Audio

Captures and encrypts audio information.

// You can specify the maxLength (in millisec) for the recording
var args = {
    maxLength: 120000
};
 
sap.VoiceRecording.audioCapture(
            function(_recording) {
                recording = _recording;
            },
            function(error) {
                console.log("An error occurred at audio capture\n\n" + JSON.stringify(error));
            },
            args
);

Playback Audio

To play an audio recording the application triggers an API function that displays an UI dialog. This UI allows you to play back or seeking position of recording..

// triggering playback screen 
recording.play(
    function() {
        console.log("Play finished Successfully\n\n");
    },
    function(error) {
        alert("An error occurred at play\n\n" + JSON.stringify(error));
    }
);

Recording ID and Metadata

You can know the recording object ID and the metadata information for the recoridng.

// recording id and metadata
var recording_id = recording.id // the id can be used to retrieve the recording after restart (the application has to store it)
     
sap.VoiceRecording.get(function(recording) {
      var restored_recording = recording;
  },
  function(error_code, extra) {
      // error callback (e.g. recoridng does not exist for the given id)
  },
  recording_id);
         
// Recroding metadata
var duration = recording.getDuration(); // retrieve the duration (in millisec)
var creationDate = recording.getCreationDate(); // retrieve the date of the recording creation
var fileName = recording.getFileName(); // returning the filename of the recording used when the file representation is generated with getAsFile() method
         
// file name can be changed by the application
recording.setFileName("new_file_name", function() {
        // success callback
    },
    funciton(){
        // error callback
    });
         
<span style="line-height: 1.42857;background-color: transparent;">)</span>

Retrieve Audio

The recordings that you capture using the sap.VoiceRecording.audioCapture method is stored with an identity (ID).

Retrieve Recording by ID

You can retrieve a specific audio recording using the sap.VoiceRecording.get method.
sap.VoiceRecording.get(
    function(recording) {
        // success callback with the retrieved Recording as parameter
    ,
    function(error_code, extra) {
        // error callback (for example, recording does not exist for the given id)
    },
    Id
);

Retrieve all Recordings

You can retrieve all audio recordings using sap.VoiceRecording.getAll method.
sap.VoiceRecording.getAll(
     function(retVal) {
         // success callback with an array of Recordings as parameter
     },
     function(error_code, extra) {
         // error callback
     }
 );

Destroy Audio

You can delete an audio recording using recording.destroy method.
recording.destroy(
       function() {
           // success callback
       },
       function(error_code, extra) {
           // error callback
       }
   );sap.VoiceRecording.destroyAll
You can also delete all audio recordings using the sap.VoiceRecording.destroyAll method
sap.VoiceRecording.destroyAll(
       function() {
           // success callback
       },
       function(error_code, extra) {
           // error callback
       }
   );

Delete Decrypted File (Windows Platform)

You can use sap.VoiceRecording.deleteFileFromPath method (additional utility) to delete a decrypted file on Windows platform after the recording.getAsFile operation. However, for Android and iOS platforms the application deletes all decrypted files once it is not in use.
sap.VoiceRecording.getAsFile(

    function(decryptedFilePath) {

        // success callback with the decrypted file path

 

        // upload or send the file, if this operation runs asynchronously, put the delete function into the callback


        // call delete

        sap.VoiceRecording.deleteFileFromPath(decryptedFilePath, function() {

                 // success callback, delete was successful

        }, function(error_code, extra) {

                 // error callback

        });

    },

    function(error_code, extra) {

        // error callback

    }

);