55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
import rtc_plugins
|
|
import time
|
|
import numpy as np
|
|
import wave
|
|
from scipy.io import wavfile
|
|
|
|
srcUserId = "srcUser12"
|
|
destUserId = "destUser12"
|
|
|
|
srcDisplayName = "srcDisplayName12"
|
|
destDisplayName = "destDisplayName12"
|
|
srcRoomId = "srcRoom12"
|
|
#destRoomId = "destRoomId12"
|
|
destRoomId = srcRoomId
|
|
srcChannelIndex = 46
|
|
destChannelIndex = 47
|
|
def my_callback(shmName, dataSize, dataCount, sampleRate, numChannels, channelIndex):
|
|
print(f"my_callback, dataSize:{dataSize}, dataCount:{dataCount}, sampleRate:{sampleRate}, numChannels:{numChannels}, channelIndex:{channelIndex}")
|
|
print(f"data:{shmName}")
|
|
print("after my_callback_r")
|
|
ret = rtc_plugins.init(srcUserId, srcDisplayName, srcRoomId, my_callback)
|
|
if ret != 0:
|
|
print(f"init fail, ret:{ret}")
|
|
exit(1)
|
|
ret = rtc_plugins.initSend(srcRoomId, destRoomId, destChannelIndex, 1)
|
|
if ret != 0:
|
|
print(f"initSend fail, ret:{ret}")
|
|
exit(1)
|
|
#audioData = np.array([0, 1, -1, 0], dtype=np.int16)
|
|
sampleRate, audioData = wavfile.read("xusample1.wav")
|
|
print(f"sampleRate:{sampleRate} HZ")
|
|
print(f"shape:{audioData.shape}")
|
|
print(f"type:{audioData.dtype}")
|
|
if audioData.dtype != np.int16:
|
|
audioData = (audioData * 32767).astype(np.int16)
|
|
ret = rtc_plugins.sendCustomAudioData(destChannelIndex, audioData, sampleRate, 1, len(audioData))
|
|
if ret != 0:
|
|
print(f"send fail, ret:{ret}")
|
|
#ret = rtc_plugins.initRecv(srcRoomId, srcUserId, srcChannelIndex)
|
|
#if ret != 0:
|
|
# print(f"initRecv fail, ret:{ret}")
|
|
# exit(1)
|
|
for i in range(100):
|
|
ret = rtc_plugins.sendCustomAudioData(destChannelIndex, audioData, sampleRate, 1, len(audioData))
|
|
if ret != 0:
|
|
print(f"send fail, ret:{ret}")
|
|
|
|
#size = rtc_plugins.getSize()
|
|
#print(f"data size:{size}")
|
|
#frame = rtc_plugins.getListData()
|
|
#print(f"get frame:{frame}")
|
|
#dataCount = rtc_plugins.getDataCount()
|
|
#print(f"data count:{dataCount}")
|
|
time.sleep(3)
|