Discussions

Ask a Question
Back to All

[Streaming API] Avatar doesn't speak according to sent text

As title, I send a phrase which is generated using my LLM model, and ask avatar to speak accordingly. But what the avatar speaks doesn't follow the text completely.
I wanna build an avatar interface having avatar and message on it, so i want the text to be exactly same as speak.
I'm using the following voice id (Chinese voice):

'voice': {'voice_id': '3b1633a466c44379bf8b5a2884727588'}

here's my send task code:

@app.route('/send-task', methods=['POST'])
def send_task():
    headers = {
        'accept': 'application/json',
        'content-type': 'application/json',
        'x-api-key': HEYGEN_API_KEY
    }
    data = request.json

    if 'session_id' not in data or 'text' not in data:
        return jsonify({"error": "Missing required fields: session_id and text"}), 400

    try:
        chatbot_text = get_openai_response(data['text'])

        heygen_response = requests.post(
            'https://api.heygen.com/v1/streaming.task',
            headers=headers,
            json={'session_id': data['session_id'],'task_type': 'repeat', 'text': chatbot_text}
        )

        if heygen_response.status_code != 200:
            print(f"Error sending task to HeyGen: {heygen_response.status_code} {heygen_response.text}")
            return jsonify({"error": "Failed to send task", "details": heygen_response.text}), heygen_response.status_code

        return jsonify(heygen_response.json())

    except requests.exceptions.RequestException as e:
        print(f"Exception during requests: {e}")
        return jsonify({"error": "Request failed", "details": str(e)}), 500
    except Exception as e:
        print(f"General exception occurred: {e}")
        return jsonify({"error": "Internal server error", "details": str(e)}), 500

possible root cause?