diff --git a/core/src/ten_runtime/binding/python/native/msg/audio_frame.c b/core/src/ten_runtime/binding/python/native/msg/audio_frame.c index 85cb2afd28..7a7ed9fcb4 100644 --- a/core/src/ten_runtime/binding/python/native/msg/audio_frame.c +++ b/core/src/ten_runtime/binding/python/native/msg/audio_frame.c @@ -205,13 +205,10 @@ PyObject *ten_py_audio_frame_set_timestamp(PyObject *self, PyObject *args) { "Invalid argument."); int64_t timestamp = 0; - - if (!PyLong_Check(args)) { - return NULL; + if (!PyArg_ParseTuple(args, "L", ×tamp)) { + return ten_py_raise_py_value_error_exception("Invalid timestamp."); } - timestamp = PyLong_AsLongLong(args); - ten_audio_frame_set_timestamp(py_audio_frame->msg.c_msg, timestamp); Py_RETURN_NONE; diff --git a/tests/ten_runtime/integration/python/send_recv_pcm_python/send_recv_pcm_python_app/ten_packages/extension/default_extension_python/extension.py b/tests/ten_runtime/integration/python/send_recv_pcm_python/send_recv_pcm_python_app/ten_packages/extension/default_extension_python/extension.py index b0af6734a2..ec3c61c88a 100644 --- a/tests/ten_runtime/integration/python/send_recv_pcm_python/send_recv_pcm_python_app/ten_packages/extension/default_extension_python/extension.py +++ b/tests/ten_runtime/integration/python/send_recv_pcm_python/send_recv_pcm_python_app/ten_packages/extension/default_extension_python/extension.py @@ -4,6 +4,7 @@ # Licensed under the Apache License, Version 2.0, with certain conditions. # Refer to the "LICENSE" file in the root directory for more information. # +import time from ten import ( Extension, TenEnv, @@ -32,6 +33,8 @@ def on_start(self, ten_env: TenEnv) -> None: ) print("audio duration: ", len(self.audio)) + self.start_time = int(time.time() * 1000) + ten_env.on_start_done() def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: @@ -50,6 +53,10 @@ def on_cmd(self, ten_env: TenEnv, cmd: Cmd) -> None: audio_frame.set_sample_rate(16000) audio_frame.set_number_of_channels(1) audio_frame.set_samples_per_channel(160) + + timestamp = int(time.time() * 1000) + audio_frame.set_timestamp(timestamp) + audio_frame.alloc_buf(len(pcm_data)) buf = audio_frame.lock_buf() buf[: len(pcm_data)] = pcm_data @@ -64,6 +71,11 @@ def on_audio_frame(self, ten_env: TenEnv, audio_frame: AudioFrame) -> None: assert audio_frame.get_number_of_channels() == 1 assert audio_frame.get_samples_per_channel() == 160 + timestamp = audio_frame.get_timestamp() + + current_time = int(time.time() * 1000) + assert current_time >= timestamp >= self.start_time + buf = audio_frame.get_buf() assert buf[: len(buf)] == self.audio[0:10].raw_data