REST API took too long

Hello. I am currently working on a Python REST API project where each audio playback action involves selecting a sound, adding a keyframe for emotion, and then playing the sound. This process requires making three REST API calls, each taking 2.5 seconds, totaling 7.5 seconds per playback. This seems a bit lengthy, and I am wondering if there are any alternative methods to achieve faster performance.

Here’s how I am currently writing the code in python:
import requests
import json
result =“http://localhost:8011/A2F/Player/SetTrack”, data).json()
result =“http://localhost:8011/A2F/A2E/AddKeys”, data).json()
result =“http://localhost:8011/A2F/Player/Play”, data).json()

Additionally, I have noticed that after adding a keyframe, when I close and reopen the program, the keyframe for that specific track is lost. Is there a way to save these keyframes so they are preserved across program restarts?

I would greatly appreciate any suggestions or insights on how to optimize the REST API for faster performance and how to preserve keyframes after a2f startup.

Thank you for your help!

I’ll ask the dev team about the REST API speed. But keyframes are preserved when I save and reopen the file. Have you saved the file?

I tried to save the file, but it seems like it didn’t save successfully. The top bar still shows the asterisk.kit_20240321_103555.log (725.2 KB)
By the way, Can REST API saving .USD file?

Yes sorry, there’s no Save function in Rest API. But good news is you could add that yourself. It’s very similar to the Load function which can be found in the Audio2Face’s installation folder, a path like this: C:\Users\{USER}\AppData\Local\ov\pkg\prod-audio2face-2023.2.0\exts\omni.audio2face.utility\omni\audio2face\utility\scripts\

1 Like

You can add this function to end of to add Save functionality to REST API:"/Save", summary="Save the current stage")
async def save_stage():

    usd_context = omni.usd.get_context()
    (result, error, saved_layers) = await usd_context.save_stage_async()

    if not result:
        return {"status": "ERROR", "message": error}

    return {"status": "OK", "message": "Succeeded"}
1 Like

Thank you. I will try that. As for the issue with saving files, do you happen to know how to fix it?

The solution above is in fact for saving files. But we don’t have a solution for the slowness yet.

1 Like

Sorry, I mean I’m add keyframes and save a file. After that I’m loading a same .USD file and found that my key frame are missing but the value of keyframe persist. and the title bar always has asterisk after I save a file.

So I think my audio2face have a save problem. how do I fix this?

I just tested this and it saves the file properly. Here’s the file after edits (rename the extension to py):

routes.txt (1.8 KB)

And here’s the contents of the test file:

    # Open an Audio2Face USD file
    open_data = {
        "file_name": "E:/test.usd"`
    result ="http://localhost:8011/A2F/USD/Load", json=open_data).json()

    # Add some emotion keyframes
    add_keys_data = {
        "a2f_instance": "/World/audio2face/CoreFullface",
        "keys": [
        "values": [
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
        "as_timestamps": False
    result ="http://localhost:8011/A2F/A2E/AddKeys", json=add_keys_data).json()

    # Save the file
    save_data = {
        "file_name": "E:/test.usd",
        "overwrite": True        
    result ="http://localhost:8011/A2F/USD/Save", save_data).json()

Thank you! I can save via REST API now!
Last question. My keyframe still missing after reopen programs.
Picture before saving:

Picture after saving and reopen program:

How can I fix this?

Oh sorry I missed json keyword argument when calling the Save endpoint. It should looks something like this:"http://localhost:8011/A2F/USD/Save", json=save_data).json()

Not this:"http://localhost:8011/A2F/USD/Save", save_data).json()

I figured it out. It turned out that the keyframe are missing because I use .wav filename with non-English language. sorry for trouble you and thank you for your time.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.