Comments (11)
There's a command line tool called sox that makes it easy to convert audio files to the format needed by gosip, which is signed linear 16-bit samples at 8khz. For example:
wget https://justine.storage.googleapis.com/numbers.mp3
sox numbers.mp3 -c1 -traw -esigned -b16 -r8000 numbers.s16
play numbers.s16
To get started playing audio files in a telephone calls, you can modify the fone/main.go example so it reads audio from a file rather than your microphone. The ticker.C channel is triggered every 20 milliseconds. Each time that happens, you need to read 320 bytes from the file and pass it along to rtp.Send().
I recommend the audio files be converted to s16 beforehand, so decoding is a one-time cost. If you want to play arbitrary audio formats on the fly, one thing that works great is spawning sox as a subprocess and reading the samples via a pipe. That should minimize the chance of cpu-bound audio decoding disrupting the event loop, which for PSTN calls must behave like real time.
from gosip.
Can you provide the param format?
or For example, like "username@host"
main.go need "requestURIString" param
from gosip.
The URI format depends.
If you're calling the PSTN you need to use a service like Flowroute. If you do that they'll give you a prefix. If you wanted to dial a number in New York it'd look something like this:
$ fone sip:12345678*[email protected]
If you want to dial a software telephone, usually they'll speak sip natively and the SIP URI will end up looking more like an email address.
from gosip.
me try "go run ./fone/main.go sip:[email protected]"
but it return:
panic: Connection refused
when run "makePulseAudio(C.PA_STREAM_RECORD, requestURIString)"
me running in docker,whether the influence?
from gosip.
I would recommend contacting your local administrator and troubleshooting the problem on your end.
from gosip.
me find fone/main.go, but only find use mic
how to read music file? me generated the numbers.s16, but i don't know the way to open it
from gosip.
Open it as a normal file using the Go standard library.
Please note this project supports gosip but we can't provide technical support in general.
from gosip.
Thank you very much for your answer
from gosip.
Thx you @jart for your awesome library!
I'm using the echo_test example code to make a SIP phone call from a Go application to another soft phone. I have FreeSwitch configured, and the Go app successfully send INVITE to soft phone, but I have trouble and really need your help: I can't hear anything from soft phone
Some clues
1/ Here is my modified code
Note: I try so set size=320 (at line 159) but it's not work!
2/ The audio file is in right format:
play ../assets/bot_greeting.wav
play WARN alsa: can't encode 0-bit Unknown or not applicable
../assets/bot_greeting.wav:
File Size: 72.2k Bit Rate: 128k
Encoding: Signed PCM
Channels: 1 @ 16-bit
Samplerate: 8000Hz
Replaygain: off
Duration: 00:00:04.51
In:100% 00:00:04.51 [00:00:00.00] Out:36.1k [ | ] Hd:5.1 Clip:0
Done.
Note: I also try these but no luck:
- Using
numbers.s16
audio file - Ulaw converting:
frameout[rtp.HeaderSize+n] = byte(dsp.LinearToUlaw(int64(raw_audio[raw_audio_idx])))
3/ Application log
➜ test git:(dev) ✗ go run .
test:main() begin...
2022/11/15 17:59:55 >>> 10.124.68.213:5080
INVITE sip:[email protected]:5080 SIP/2.0
From: Echo Test <sip:10.124.68.213:33684>;tag=ab3072e56f7f
To: <sip:10.124.68.213:5080>
Via: SIP/2.0/UDP 10.124.68.213:33684;branch=z9hG4bK-e83efd2990b5
Contact: <sip:10.124.68.213:33684>
Call-ID: 912685b5-8ce3-469e-a0ce-4537ebe4d35c
CSeq: 17257 INVITE
User-Agent: gosip/1.o
Max-Forwards: 70
Content-Type: application/sdp
Content-Length: 240
v=0
o=- 1929021139 1929021139 IN IP4 10.124.68.213
s=my people call themselves dark angels
c=IN IP4 10.124.68.213
t=0 0
m=audio 49184 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=sendrecv
2022/11/15 17:59:55 <<< 10.124.68.213:5080
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.124.68.213:33684;branch=z9hG4bK-e83efd2990b5
From: Echo Test <sip:10.124.68.213:33684>;tag=ab3072e56f7f
To: <sip:10.124.68.213:5080>
Call-ID: 912685b5-8ce3-469e-a0ce-4537ebe4d35c
CSeq: 17257 INVITE
User-Agent: FreeSWITCH-mod_sofia/1.10.5-release+git~20200818T185121Z~25569c1631~64bit
Content-Length: 0
2022/11/15 17:59:58 <<< 10.124.68.213:5080
SIP/2.0 183 Session Progress
Via: SIP/2.0/UDP 10.124.68.213:33684;branch=z9hG4bK-e83efd2990b5
From: Echo Test <sip:10.124.68.213:33684>;tag=ab3072e56f7f
To: <sip:10.124.68.213:5080>;tag=Q0UUBv4N3BSjQ
Call-ID: 912685b5-8ce3-469e-a0ce-4537ebe4d35c
CSeq: 17257 INVITE
Contact: <sip:[email protected]:5080;transport=udp>
User-Agent: FreeSWITCH-mod_sofia/1.10.5-release+git~20200818T185121Z~25569c1631~64bit
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 222
Remote-Party-ID: "1001" <sip:[email protected]>;party=calling;privacy=off;screen=no
v=0
o=FreeSWITCH 1668493614 1668493615 IN IP4 10.124.68.213
s=FreeSWITCH
c=IN IP4 10.124.68.213
t=0 0
m=audio 16384 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
2022/11/15 17:59:58 wanted 200 ok but got:183Session Progress... retry in 5s
2022/11/15 18:00:03 <<< 10.124.68.213:5080
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.124.68.213:33684;branch=z9hG4bK-e83efd2990b5
From: Echo Test <sip:10.124.68.213:33684>;tag=ab3072e56f7f
To: <sip:10.124.68.213:5080>;tag=Q0UUBv4N3BSjQ
Call-ID: 912685b5-8ce3-469e-a0ce-4537ebe4d35c
CSeq: 17257 INVITE
Contact: <sip:[email protected]:5080;transport=udp>
User-Agent: FreeSWITCH-mod_sofia/1.10.5-release+git~20200818T185121Z~25569c1631~64bit
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY
Supported: timer, path, replaces
Allow-Events: talk, hold, conference, refer
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 222
Remote-Party-ID: "Outbound Call" <sip:[email protected]>;party=calling;privacy=off;screen=no
v=0
o=FreeSWITCH 1668493614 1668493615 IN IP4 10.124.68.213
s=FreeSWITCH
c=IN IP4 10.124.68.213
t=0 0
m=audio 16384 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
2022/11/15 18:00:03 read 72238 bytes from sample audio
2022/11/15 18:00:04 written at audio idx: 8000
2022/11/15 18:00:05 written at audio idx: 16000
2022/11/15 18:00:06 written at audio idx: 24000
2022/11/15 18:00:07 written at audio idx: 32000
2022/11/15 18:00:08 written at audio idx: 40000
2022/11/15 18:00:09 written at audio idx: 48000
2022/11/15 18:00:10 written at audio idx: 56000
2022/11/15 18:00:11 written at audio idx: 64000
2022/11/15 18:00:12 written at audio idx: 72000
2022/11/15 18:00:12 Going to hangup...
2022/11/15 18:00:12 End call !!!
test:main() end!
from gosip.
Hi @yaosiqi525 , did you get it work with your audio file?
from gosip.
@yaosiqi525 @hoangtuan151 you can try to get this library(zaf/g711)
from gosip.
Related Issues (20)
- Move dialog into own package HOT 6
- Decouple SDP parser from SIP parser HOT 13
- Support Wildcard Contact HOT 6
- 有没有对应的文档? HOT 2
- Extension Header parse failed HOT 1
- Via port=0
- Future plans for SIP over TLS? HOT 1
- To will be parsed as null,This message is generated by mac software, telephone。
- rtp header read bug
- Implementing a sip server, receiving calls
- Compilation issue: missing function body HOT 7
- util.GenerateCallID() always generates the same UUIDs
- Question: How to parse DTMF?
- How to make all SIP traffic use an outbound proxy?
- Newly published Go library for SIP/RTP/SDP/DTMF/DSP HOT 6
- Is this repository still being maintained? HOT 2
- Set up CI system HOT 7
- Handle empty SDP Addr TODO HOT 1
- Fuzzing SIP parser HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gosip.