add demo:play audio in python after migu rtc
This commit is contained in:
parent
95969ffcc8
commit
f688c690aa
|
@ -0,0 +1,45 @@
|
|||
import rtc_plugins
|
||||
import time
|
||||
import sounddevice as sd
|
||||
import numpy as np
|
||||
import mmap
|
||||
import os
|
||||
from ctypes import c_int16
|
||||
import struct
|
||||
|
||||
srcUserId = "srcUser12"
|
||||
destUserId = "destUser12"
|
||||
|
||||
srcDisplayName = "srcDisplayName12"
|
||||
destDisplayName = "destDisplayName12"
|
||||
srcRoomId = "srcRoom12"
|
||||
#destRoomId = "destRoomId12"
|
||||
destRoomId = srcRoomId
|
||||
srcChannelIndex = 46
|
||||
destChannelIndex = 47
|
||||
def my_callback_r(shmName, dataSize, dataCount, sampleRate, numChannels, channelIndex):
|
||||
print(f"my_callback_r, dataSize:{dataSize}, dataCount:{dataCount}, sampleRate:{sampleRate}, numChannels:{numChannels}, channelIndex:{channelIndex}")
|
||||
print(f"data:{shmName}")
|
||||
print("after my_callback_r")
|
||||
|
||||
ret = rtc_plugins.init(destUserId, destDisplayName, destRoomId, my_callback_r)
|
||||
if ret != 0:
|
||||
print(f"init fail, ret:{ret}")
|
||||
exit(1)
|
||||
ret = rtc_plugins.initRecv(destRoomId, srcUserId, destChannelIndex)
|
||||
if ret != 0:
|
||||
print(f"initRecv fail, ret:{ret}")
|
||||
exit(1)
|
||||
#ret = rtc_plugins.initSend(destRoomId, srcRoomId, srcChannelIndex, 1)
|
||||
#if ret != 0:
|
||||
# print(f"initSend fail, ret:{ret}")
|
||||
# exit(1)
|
||||
|
||||
sampleRate = 16000
|
||||
while True:
|
||||
frame = rtc_plugins.getListData()
|
||||
sd.play(frame, sampleRate)
|
||||
sd.wait()
|
||||
print(f"get frame:{frame}")
|
||||
|
||||
time.sleep(0.005)
|
|
@ -36,14 +36,14 @@ if audioData.dtype != 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)
|
||||
#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}")
|
||||
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}")
|
||||
|
|
|
@ -729,14 +729,10 @@ np::ndarray RTCContext::getNumpyData() {
|
|||
|
||||
}
|
||||
bp::list RTCContext::getListData() {
|
||||
std::cout << "step1" << std::endl;
|
||||
std::lock_guard<std::mutex> lock(dataMutex_);
|
||||
RetAudioFrame frame = getData();
|
||||
std::cout << "step2" << std::endl;
|
||||
int16_t* dataPtr = frame.data.get(); // 你的数据指针
|
||||
std::cout << "step3" << std::endl;
|
||||
size_t length = frame.dataCount; // 数据长度
|
||||
std::cout << "step4" << std::endl;
|
||||
bp::list result;
|
||||
if (dataPtr && length > 0) {
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
|
|
Loading…
Reference in New Issue