record audio

This commit is contained in:
DJ2LS 2022-12-26 12:11:59 +01:00
parent 424384c7ed
commit c0e4f14da0
7 changed files with 64 additions and 3 deletions

View File

@ -268,7 +268,7 @@ jobs:
# if: matrix.os == 'ubuntu-20.04'
if: ${{startsWith(matrix.os, 'ubuntu')}}
run: |
sudo apt install -y portaudio19-dev libhamlib-dev libhamlib-utils build-essential cmake python3-libhamlib2
sudo apt install -y portaudio19-dev libhamlib-dev libhamlib-utils build-essential cmake python3-libhamlib2 patchelf
- name: Install MacOS pyAudio
if: ${{startsWith(matrix.os, 'macos')}}

View File

@ -38,6 +38,20 @@ var dbfs_level_raw = 0
window.addEventListener('DOMContentLoaded', () => {
// start stop audio recording event listener
document.getElementById("startStopRecording").addEventListener("click", () => {
let Data = {
type: "set",
command: "record_audio",
state: "True",
};
ipcRenderer.send('run-tnc-command', Data);
});
document.getElementById('received_files_folder').addEventListener('click', () => {
ipcRenderer.send('get-folder-path',{
@ -96,8 +110,8 @@ document.getElementById('openReceivedFilesFolder').addEventListener('click', ()
// hamlib settings
document.getElementById('hamlib_deviceid').value = config.hamlib_deviceid;
set_setting_switch("enable_hamlib_deviceport", "hamlib_deviceport", config.enable_hamlib_deviceport)
set_setting_switch("enable_hamlib_ptt_port", "hamlib_ptt_port", config.enable_hamlib_ptt_port)
set_setting_switch("enable_hamlib_deviceport", "hamlib_deviceport", config.enable_hamlib_deviceport)
set_setting_switch("enable_hamlib_ptt_port", "hamlib_ptt_port", config.enable_hamlib_ptt_port)
document.getElementById('hamlib_serialspeed').value = config.hamlib_serialspeed;
set_setting_switch("enable_hamlib_serialspeed", "hamlib_serialspeed", config.enable_hamlib_serialspeed)
@ -1441,6 +1455,22 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
document.getElementById("ptt_state").className = "btn btn-sm btn-secondary";
}
// AUDIO RECORDING
if (arg.audio_recording == 'True') {
document.getElementById("startStopRecording").className = "btn btn-sm btn-danger";
document.getElementById("startStopRecording").innerHTML = "Stop Rec"
} else if (arg.ptt_state == 'False') {
document.getElementById("startStopRecording").className = "btn btn-sm btn-danger";
document.getElementById("startStopRecording").innerHTML = "Start Rec"
} else {
document.getElementById("startStopRecording").className = "btn btn-sm btn-danger";
document.getElementById("startStopRecording").innerHTML = "Start Rec"
}
// CHANNEL BUSY STATE
if (arg.channel_busy == 'True') {
document.getElementById("channel_busy").className = "btn btn-sm btn-danger";

View File

@ -227,6 +227,8 @@ client.on('data', function(socketdata) {
stations: data['stations'],
beacon_state: data['beacon_state'],
hamlib_status: data['hamlib_status'],
listen: data['listen'],
audio_recording: data['audio_recording'],
};
ipcRenderer.send('request-update-tnc-state', Data);

View File

@ -768,6 +768,8 @@
<div class="card text-dark mb-1">
<div class="card-header p-1"><i class="bi bi-volume-up" style="font-size: 1rem; color: black;"></i> <strong>AUDIO LEVEL</strong>
<button type="button" id="audioModalButton" data-bs-toggle="modal" data-bs-target="#audioModal" class="btn btn-sm btn-secondary">Tune</button>
<button type="button" id="startStopRecording" class="btn btn-sm btn-danger">Rec</button>
</div>
<div class="card-body p-2">
<div class="progress mb-0" style="height: 15px;">

View File

@ -67,6 +67,7 @@ class RF:
self.AUDIO_CHANNELS = 1
self.MODE = 0
# Locking state for mod out so buffer will be filled before we can use it
# https://github.com/DJ2LS/FreeDATA/issues/127
# https://github.com/DJ2LS/FreeDATA/issues/99
@ -355,6 +356,10 @@ class RF:
x = np.frombuffer(data_in48k, dtype=np.int16)
x = self.resampler.resample48_to_8(x)
# audio recording for debugging purposes
if static.AUDIO_RECORD:
static.AUDIO_RECORD_FILE.write(x)
# Avoid decoding when transmitting to reduce CPU
# TODO: Overriding this for testing purposes
# if not static.TRANSMITTING:

View File

@ -227,6 +227,25 @@ def process_tnc_commands(data):
"[SCK] CQ command execution error", e=err, command=received_json
)
# START STOP AUDIO RECORDING -----------------------------------------------------
if received_json["type"] == "set" and received_json["command"] == "record_audio":
try:
if received_json["state"] in ['true', 'True', True]:
static.AUDIO_RECORD_FILE = open(f"{int(time.time())}_audio_recording", 'wb')
static.AUDIO_RECORD = True
else:
static.AUDIO_RECORD = False
static.AUDIO_RECORD_FILE.close()
command_response("respond_to_call", True)
except Exception as err:
command_response("respond_to_call", False)
log.warning(
"[SCK] CQ command execution error", e=err, command=received_json
)
# SET ENABLE/DISABLE RESPOND TO CALL -----------------------------------------------------
if received_json["type"] == "set" and received_json["command"] == "respond_to_call":
try:
@ -612,6 +631,7 @@ def send_tnc_state():
"dxgrid": str(static.DXGRID, encoding),
"hamlib_status": static.HAMLIB_STATUS,
"listen": str(static.LISTEN),
"audio_recording": str(static.AUDIO_RECORD),
}
# add heard stations to heard stations object

View File

@ -82,6 +82,8 @@ AUDIO_INPUT_DEVICES: list = []
AUDIO_OUTPUT_DEVICES: list = []
AUDIO_INPUT_DEVICE: int = -2
AUDIO_OUTPUT_DEVICE: int = -2
AUDIO_RECORD: bool = False
AUDIO_RECORD_FILE = ''
BUFFER_OVERFLOW_COUNTER: list = [0, 0, 0, 0, 0]
AUDIO_DBFS: int = 0