rtc_plugins/test_send.py

30 lines
961 B
Python
Raw Normal View History

2025-04-09 18:13:36 +08:00
import rtc_plugins
import time
2025-04-10 09:07:06 +08:00
import numpy as np
2025-04-09 18:13:36 +08:00
srcUserId = "srcUser1"
destUserId = "destUser1"
srcDisplayName = "srcDisplayName1"
destDisplayName = "destDisplayName1"
srcRoomId = "srcRoom1"
destRoomId = "destRoomId1"
srcChannelIndex = 42
destChannelIndex = 43
def my_callback(npData, dataCount, sampleRate, numChannels, channelIndex):
print(f"dataCount:{dataCount}, sampleRate:{sampleRate}, numChannels:{numChannels}, channelIndex:{channelIndex}")
ret = rtc_plugins.init(srcUserId, srcDisplayName, srcRoomId, my_callback)
if ret != 0:
print(f"init fail, ret:{ret}")
exit(1)
2025-04-15 17:51:40 +08:00
ret = rtc_plugins.initSend(srcRoomId, destRoomId, destChannelIndex, 1)
2025-04-09 18:13:36 +08:00
if ret != 0:
print(f"initSend fail, ret:{ret}")
exit(1)
2025-04-10 09:21:12 +08:00
audioData = np.array([0, 1, -1, 0], dtype=np.int16)
2025-04-09 18:13:36 +08:00
while True:
2025-04-10 09:07:06 +08:00
ret = rtc_plugins.sendCustomAudioData(destChannelIndex, audioData, 48000, 1, len(audioData))
2025-04-09 18:13:36 +08:00
if ret != 0:
print(f"send fail, ret:{ret}")
time.sleep(3)