[How-To] Record Calls
-
Before using these scripts read the DISCLAIMER here.
To perform this how-to you must be familiar with the command line, as I mentioned in other post ( @klh excuse the off-topic ) I created a service to record all calls.
The first step is run :
arecord file.wav
make a call and then stop recording with Ctrl+C
play recorded call, if voices are not clearly heard unfortunately this how-to is already over
otherwise you can proceed ...
- You have to create callrecorder service, to create it mount root in read/write mode :
sudo mount -o remount,rw /
sudo nano /etc/init.d/callrecorder :
#! /bin/sh ### BEGIN INIT INFO # Provides: callrecorder # Required-Start: $local_fs # Required-Stop: &local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Call Recorder # Description: Call Recorder Daemon ### END INIT INFO # Written by Br1 <br1@spacelinux.it> case "$1" in start) echo "Call recorder starting ..." bash -c 'cd /home/phablet/.callrec/ && ./prepare-sh &' ;; stop) pkill manager.sh ; pkill ini.sh ; pkill ter.sh ; pkill ris.sh ; rm /home/phablet/.callrec/CallRecorder/.*swp 2> /dev/null ; rm /home/phablet/aRam/Rec_Call/.*swp 2> /dev/null ; echo "Call recorder stopped !" ;; *) echo "Usage: sudo service callrecorder {start|stop}" exit 1 ;; esac exit 0
and set permission with : sudo chmod 755 /etc/init.d/callrecorder
enable autostart with : sudo update-rc.d callrecorder defaults
( if you want disable it : sudo update-rc.d -f callrecorder remove)-
you have to create 3 directories :
/home/phablet/aRam
/home/phablet/.callrec
/home/phablet/MyRec -
and you also have to create 5 scripts :
1 - nano /home phablet/.callrec/prepare-sh :
#!/bin/sh # ----- start/stop service section ----- # # check service status if ps aux | grep -q "[m]anager.sh" ; then echo " ! Service already running !" ; exit fi # check if ramdisk is mounted and exec scripts if grep -qs '/phablet/aRam ' /proc/mounts ; then cd /home/phablet/aRam/Rec_Call ; ./manager.sh & ./ini.sh & ./ter.sh & ./ris.sh & exit fi # ----- boot section ----- # /bin/sleep 10 ; # clear cache and buffer sh -c "free && sync && echo 3 > /proc/sys/vm/drop_caches && free" ; # create ramdisk mount -t tmpfs -o size=200M tmpfs /home/phablet/aRam ; # create directory mkdir -p /home/phablet/aRam/Rec_Call ; # copy scripts to directory just created cp -rp /home/phablet/.callrec/*.sh /home/phablet/aRam/Rec_Call ; # and exec them cd /home/phablet/aRam/Rec_Call ; ./manager.sh & ./ini.sh & ./ter.sh & ./ris.sh & exit
2 - nano /home/phablet/.callrec/manager.sh :
#!/bin/sh while true do FL1=/home/phablet/aRam/Rec_Call/fl1 ; FL2=/home/phablet/aRam/Rec_Call/fl2 ; FL3=/home/phablet/aRam/Rec_Call/fl3 ; RecDir=/home/phablet/MyRec ; HomDir=/home/phablet/aRam/Rec_Call ; # if fl1 exist ini.sh intercepted outgoing or incoming call if [ -f "$FL1" ]; then # deletes temporary file and starts recording as phablet user (with .new extension) rm -f $FL1 ; su phablet -s /usr/bin/arecord /home/phablet/MyRec/"$(date +%d_%m_%y__%H_%M_%S)".wav.new & fi # if fl2 exist call has ended if [ -f "$FL2" ]; then # deletes the temporary file and stop recording rm -f $FL2 ; pkill -f arecord ; sleep 0.2 ; # if fl3 exist call was answered if [ -f "$FL3" ]; then # delete .new extension and exec three scripts rm -f $FL3 ; mv $RecDir/*.new $RecDir/"$(date +%d_%m_%y__%H_%M_%S)".wav ; $HomDir/ini.sh & $HomDir/ter.sh & $HomDir/ris.sh & else # call was not answered # delete recording and exec two scripts rm $RecDir/*.new ; $HomDir/ini.sh & $HomDir/ter.sh & fi fi sleep 1 ; done ;
3 - nano /home/phablet/.callrec/ini.sh :
#!/bin/sh cd /home/phablet/aRam/Rec_Call ; inicmline="dbus-monitor --system interface=org.ofono.VoiceCallManager member=CallAdded" ; $inicmline | while read line do echo $line | grep "incoming\|dialing" if [ "$?" -eq "0" ]; then echo "";/bin/touch fl1;echo ""; break fi done
4 - nano /home/phablet/.callrec/ter.sh :
#!/bin/sh cd /home/phablet/aRam/Rec_Call ; tercmline="dbus-monitor --system interface=org.ofono.VoiceCall member=PropertyChanged" ; $tercmline | while read line do echo $line | grep "disconnected" if [ "$?" -eq "0" ]; then echo "";/bin/touch fl2;echo ""; break fi done
5 - nano /home/phablet/.callrec/ris.sh :
#!/bin/sh cd /home/phablet/aRam/Rec_Call ; riscmline="dbus-monitor --system interface=org.ofono.VoiceCall member=PropertyChanged" ; $riscmline | while read line do echo $line | grep "StartTime" if [ "$?" -eq "0" ]; then echo "";/bin/touch fl3;echo ""; break fi done
make all scripts executable with chmod u+x
- you can start the service with : sudo service callrecorder start
or reboot device
-------- overview --- how it works --------
- callrecorder service run prepare-sh script and allows you to stop the execution by terminating 4 running processes
- prepare-sh creates ramdisk in order to speed up read/write operations, copies 4 scripts on ramdisk and executes them, some more details in scripts comments (any text after a hash sign '#')
I was planning to make a single script always running and it didn't work, so I created a four scripts system :
-
manager.sh handles three child/processes scripts, each of them intercepts a string (dbus-monitor) creates temporary file and exit
-
ini.sh intercepts outgoing and incoming calls
-
ris.sh intercepts the start of phone communication (call was answered)
-
ter.sh intercepts the end of phone communication
the last two would suffice, however, starting the recording at the beginning of phone communication, sometimes 1/2 seconds are lost ... so I preferred to start the recording on outgoing/incoming calls (if there is no answer recording is deleted)
Calls are recorded in uncompressed format (wav) but if you periodically delete the recordings there will be no problems ... I prefer to convert them (to ogg format) daily with crontab managed script, if you want I attach it, but it will be necessary install ffmpeg (via apt), I will complete it to delete recordings older than 40 days.
I hope I did not forget anything ... English is not my natural language, if something is not clear, you ask and I will try to explain better.
I have not detected abnormal battery drain, maybe these scripts can be improved, anyway callrecorder service works fine on my Xiaomi Mi A2.
I want to say Thanks to all volunteers working on UBports project, having linux on a smartphone is very rewarding
-
-
@br1 Thank you for your effort. Isn't that a good basis for doing a .click? As it stands, this will only be of interest to qualified users. Personally, the recorder allows me to record smartphone conversations quite easily.
-
@domubpkm said in [How-To] Record Calls:
Isn't that a good basis for doing a .click?
I donβt know and Iβd like to know ...
I would also love to create a GUI for shell scripting but I donβt think itβs possible. -
-
--------- update ---------
@domubpkm said in [How-To] Record Calls:
As it stands, this will only be of interest to qualified users
I've made it as easy as possible, only three steps :
-
first, use morph browser to download( just click) callrecorder.tar.gz from here (in addition to above scripts contains callrec-install script)
-
second, open file manager, go to Downloads click callrecorder.tar.gz and select extract archive
-
third, to run callrec-install open terminal and type :
sudo Downloads/callrecorder/callrec-install
callrec-install script will ask you to choose :
type 1 to install callrecorder (reboot required)
type 2 to uninstall it
type 3 to exit from scriptyou don't have to do anything else.
Recorded calls are in MyRec directory, at device startup prepare.sh script will delete any that are older than 30 days.
I recommend running callrec-install to uninstall callrecorder before proceeding to ota update.
This is callrec-install script :
#!/bin/bash CRSERV=/etc/init.d/callrecorder ; # Make sure only root can run this script if [ "$(id -u)" != "0" ]; then echo " Must be run as root, you must prepend sudo !" 1>&2 exit 1 fi echo -e '\n - You can install / uninstall CallRecorder -\n' ; PS3='Please enter your choice : ' options=("Install" "Uninstall" "Quit") select opt in "${options[@]}" do case $opt in "Install") echo -e '\n Installation in progress ...\n' ; # creates 3 directories su phablet -s /bin/mkdir /home/phablet/{.callrec,aRam,MyRec} ; cp /home/phablet/Downloads/callrecorder/* /home/phablet/.callrec/ ; # change the working directory cd /home/phablet/.callrec ; # mount root in read/write mode mount -o remount,rw / ; # copy callrecorder service and enable autostart cp callrecorder /etc/init.d/ ; update-rc.d callrecorder defaults ; # roll back root in read only mode mount -o remount,ro / ; echo -e ' Installed, reboot your device !\n' ; exit 0 ;; "Uninstall") # check status if [ ! -f "$CRSERV" ]; then echo -e '\n CallRecorder is not installed !\n' ; break else # mount root in read/write mode mount -o remount,rw / ; # stop callrecorder, disable autostart and remove service file service callrecorder stop ; update-rc.d -f callrecorder remove ; rm /etc/init.d/callrecorder ; # roll back root in read only mode mount -o remount,ro / ; # delete scripts and remove directories rm -rf /home/phablet/.callrec/* ; rmdir /home/phablet/.callrec ; rm -rf /home/phablet/MyRec/* ; rmdir /home/phablet/MyRec ; rm -rf /home/phablet/aRam/* ; echo -e '\n Done, CallRecorder uninstalled !\n' exit 0 fi ;; "Quit") break ;; *) echo "invalid option $REPLY" ;; esac done
-
-
@br1 Anything that makes it user friendly is welcome, so thank you. To clarify, your recorder automatically records all conversations, correct? In what sound format?
-
@domubpkm said in [How-To] Record Calls:
To clarify, your recorder automatically records all conversations, correct? In what sound format?
Yes, that is correct, in wav format.
-
@br1 said in [How-To] Record Calls:
script will delete any that are older than 30 days.
Perhaps the option should be provided:
- automatically erase recordings after ... days (between 0 and 30 days) ? 0 = never
-
@domubpkm said in [How-To] Record Calls:
Perhaps the option should be provided:
I'll work on it ...
automatically erase recordings after ... days (between 0 and 30 days) ? 0 = never
You can use uText app " Edit and save every file on your Phone" ... open filemanager and go to .callrec directory then click prepare.sh , open with uText app and find this line :
find /home/phablet/MyRec/* -mtime +30 -exec rm {} \; 2> /dev/null ;
replace "30" with days you want
or if you want to disable automatically erase you have to prepend the line with hash sign '#'
# find /home/phablet/MyRec/* -mtime +30 -exec rm {} \; 2> /dev/null ;ΓΉ
and save file, anyway wav is an uncompressed format, a rough estimate, 1-hour call about 30 megabytes ...
-
@br1 Thanks again. I used the archive manager in ubuntu 20.04 to edit the line.
One more clarification: what do you mean by 'at de device startup' in the line 'at device startup prepare.sh script will delete any that are older than 30 days'. Does this mean every time we restart or reboot the smartphone ? So, for example, if there is no reboot for 3 months, all the records for the 3 months will be on the smartphone ?
And if we restart the smartphone after 25 days, how does the script understand this? The 30 day period is not reset? -
@domubpkm said in [How-To] Record Calls:
Does this mean every time we restart or reboot the smartphone ? So, for example, if there is no reboot for 3 months, all the records for the 3 months will be on the smartphone ?
Yes the Linux-style solution is very simple ... a small script :
#!/bin/sh find /home/phablet/MyRec/* -mtime +30 -exec rm {} \; 2> /dev/null
to be run daily via crontab ... but crontab requires (again) to mount root in read write mode, the easiest solution to avoid it is add the line to manager.sh, check would be carried out after each recording.
I'll be away for a week, but then I'll work on it.
-
@br1 These are just improvements. I test on my ultra custom rc channel and it works fine.
The wav format doesn't take up that much space because it's the lowest quality i think here. -
Sailfish has call recording built into the phone app with the push of a button. Just sayin'...
-
@bocephus Sailfish is not UT. If you have the knowledge, you can implement the mechanism you say. This will be greatly appreciated by the community. Personally, I thank all those who bring a positive point of contribution to UT on this forum.
-
As far as I'm concerned, .wav records from MyRec are not directly readable from this directory. If I copy this directory to the Music directory or to my SD card, I can.
-
@domubpkm I can read them.
-
@bolly said in [How-To] Record Calls:
I can read them
Hello.
What do you mean more specifically? What phone /channel ? -
Hello @domubpkm ,
- E4.5 stable channel.
- Installation with the script: https://forums.ubports.com/topic/8144/how-to-record-calls/4?_=1665911281738
- Open file with file explorer and preview.
-
-
@bolly Exact. Preview on the line of selected wav file works but not preview on top.
-
Hello @Br1 . I just noticed today, as it is my first try,
that the sound reproduced from the recording in loudspeaker mode is not of good quality. Do you confirm it? If so, can you make the recording speakerphone compatible?Edit 10/30 : I note that recordings are named with their recording end time. Personally, it seems more logical to me that this is the start time of a recording: that's why I rename each recording with the times contained in the call log.