抓取RTP语音流
通过freeswitch的media-bug抓取RTP语音流,udp传输到第三方语音识别等
media-bug
case SWITCH_ABC_TYPE_READ_REPLACE:
{
switch_frame_t *frame;
if ((frame = switch_core_media_bug_get_read_replace_frame(bug))) {
//switch_size_t frame_len = frame->datalen / 2;
switch_size_t frame_dlen = frame->datalen;
switch_core_media_bug_set_read_replace_frame(bug, frame);
if (frame->channels != 1)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "nonsupport channels:%d!\n",frame->channels);
return SWITCH_FALSE;
}
switch_socket_sendto(globals.sip_socket, globals.sip_server_addr, 0, frame->data, &frame_dlen);
}
}
break;
udp-server
connection, err := net.ListenUDP("udp", &net.UDPAddr{
IP: net.IPv4(0, 0, 0, 0),
Port: 9527,
})
if err != nil {
fmt.Println("connection failed, err:", err)
return
}
defer connection.Close()
for {
buffer := make([]byte, 1024)
n, _, err := connection.ReadFromUDP(buffer)
if err != nil {
fmt.Println("error: ", err)
break
} else {
//sendData(nlsSession, g711.EncodeUlaw(buffer[:n]))
//sendData(nlsSession, g711.DecodeUlaw(g711.EncodeUlaw(buffer[:n])))
sendData(nlsSession, buffer[:n])
}
}