Skip to content

i2srec and i2srec2 stop recording after 30 seconds #24657

@wyrucz

Description

@wyrucz

PROBLEM DESCRIPTION

When recording audio using either i2srec or i2srec2 the recording stops after 30 seconds. The behavior is the same when recording to a SDCard or to FlashFS.

Also the behavior of i2srec and i2srec differs slightly:
"i2srec2 /test.opus" stops the recording and outputs a record task result code: 0 Message to the console
"i2srec /test.mp3" does not send a message to the console, i2srec -? shows the recording is seemingly running past 30 seconds. When stopping the recording and checking the file, in fact only 30 seconds are recorded.

i2sstream is not experiencing this issue, it does not stop streaming mp3 or opus data.

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

  • Read the Contributing Guide and Policy and the Code of Conduct
  • Searched the problem in issues
  • Searched the problem in discussions
  • Searched the problem in the docs
  • Searched the problem in the chat
  • Problem is not scripter related, in this case open a discussion and tag gemu2015
  • Device used (e.g., Sonoff Basic): ESP32-S3-N16-R8 Development Board
  • Tasmota binary firmware version number used: _____
    • Pre-compiled
    • Self-compiled
  • Flashing tools used: esptool.py (pio to compile image)
  • Provide the output of command: Backlog Template; Module; GPIO 255:
  Configuration output here:
03:40:52.788 CMD: Backlog Template; Module; GPIO 255
03:40:52.801 RSL: RESULT = {"NAME":"ESP32S3","ARCH":"ESP32S3","GPIO":[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1],"FLAG":0,"BASE":1}
03:40:53.038 RSL: RESULT = {"Module":{"1":"ESP32S3"}}
03:40:53.241 RSL: RESULT = {"GPIO0":{"None":0},"GPIO1":{"None":0},"GPIO2":{"None":0},"GPIO3":{"None":0},"GPIO4":{"SDCard CS2":6721},"GPIO5":{"SPI MOSI2":705},"GPIO6":{"SPI CLK2":737},"GPIO7":{"SPI MISO2":673},"GPIO8":{"None":0},"GPIO9":{"None":0},"GPIO10":{"None":0},"GPIO11":{"None":0},"GPIO12":{"None":0},"GPIO13":{"None":0},"GPIO14":{"None":0},"GPIO15":{"I2S DIN1":7872},"GPIO16":{"I2S WS1":7840},"GPIO17":{"I2S BCLK1":7808},"GPIO18":{"I2S DOUT1":7776},"GPIO19":{"None":0},"GPIO20":{"None":0},"GPIO21":{"None":0},"GPIO33":{"None":0},"GPIO34":{"None":0},"GPIO35":{"None":0},"GPIO36":{"None":0},"GPIO37":{"None":0},"GPIO38":{"None":0},"GPIO39":{"None":0},"GPIO40":{"None":0},"GPIO41":{"None":0},"GPIO42":{"None":0},"GPIO43":{"None":0},"GPIO44":{"None":0},"GPIO45":{"None":0},"GPIO46":{"None":0},"GPIO47":{"None":0},"GPIO48":{"WS28121":1376}}
  • If using rules, provide the output of this command: Backlog Rule1; Rule2; Rule3:
  Rules output here:

  • Provide the output of this command: Status 0:
  STATUS 0 output here:
03:41:41.289 CMD: Status 0
03:41:41.290 RSL: STATUS = {"Status":{"Module":1,"DeviceName":"Mikrofon1","FriendlyName":["Mikrofon1"],"Topic":"tasmota_FCCB78","ButtonTopic":"0","Power":"1","PowerLock":"0","PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
03:41:41.293 RSL: STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":" ","RestartReason":"Software reset CPU","Uptime":"0T00:31:29","StartupUTC":"2026-04-19T02:10:12","Sleep":50,"CfgHolder":4617,"BootCount":36,"BCResetTime":"2026-04-03T23:04:59","SaveCount":60}}
03:41:41.295 RSL: STATUS2 = {"StatusFWR":{"Version":"15.3.0.3(TasmotaFriggel-esp32s3)","BuildDateTime":"2026-04-08T04:24:03","Core":"3.3.7","SDK":"5.3.4.260127","CpuFrequency":240,"Hardware":"ESP32-S3 v0.2","CR":"350/699"}}
03:41:41.296 RSL: STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"FileLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["IoT-WiFi",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C80001000600003C5A0A192800000000","00000080","00006000","00004000","00000000"]}}
03:41:41.303 RSL: STATUS4 = {"StatusMEM":{"ProgramSize":2443,"Free":436,"Heap":238,"StackLowMark":3,"PsrMax":5760,"PsrFree":5712,"ProgramFlashSize":16384,"FlashSize":16384,"FlashChipId":"184068","FlashFrequency":80,"FlashMode":"QIO","Features":["0809","9F8AD5DF","0005A001","B7F7BFCF","05DA9B04","E2360CC7","488800D2","20200000","D4BC480D","810A80F1","00200814"],"Drivers":"1,2,!3,4,!5,!8,9,10,11,12,!14,!16,!17,!24,26,29,!34,!35,38,!42,50,52,!59,!60,62,!63,!66,!67,!68,!73,!75,82,!86,!87,!88,!91,!121","Sensors":"1,2,3,5,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,26,31,34,37,39,40,42,43,45,51,52,55,56,58,59,64,66,67,74,85,92,95,98,103,105,109,119,127","I2CDriver":"7,8,9,10,11,12,13,14,15,17,18,20,24,29,31,36,41,42,44,46,48,58,62,65,69,76,77,82,89,97"}}
03:41:41.306 RSL: STATUS5 = {"StatusNET":{"Hostname":"tasmota-mikrofon1","IPAddress":"10.13.9.208","Gateway":"10.13.9.1","Subnetmask":"255.255.255.0","DNSServer1":"10.13.9.1","DNSServer2":"0.0.0.0","Mac":"E0:72:A1:FC:CB:78","IP6Global":"","IP6Local":"fe80::e272:a1ff:fefc:cb78%st2","Ethernet":{"Hostname":"","IPAddress":"0.0.0.0","Gateway":"0.0.0.0","Subnetmask":"0.0.0.0","DNSServer1":"10.13.9.1","DNSServer2":"0.0.0.0","Mac":"00:00:00:00:00:00","IP6Global":"","IP6Local":""},"Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":19.0}}
03:41:41.308 RSL: STATUS6 = {"StatusMQT":{"MqttHost":"","MqttPort":1883,"MqttClientMask":"DVES_%06X","MqttClient":"DVES_FCCB78","MqttUser":"DVES_USER","MqttCount":0,"MqttTLS":0,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
03:41:41.309 RSL: STATUS7 = {"StatusTIM":{"UTC":"2026-04-19T02:41:41Z","Local":"2026-04-19T03:41:41","StartDST":"2026-03-29T02:00:00","EndDST":"2026-10-25T03:00:00","Timezone":"+01:00","Sunrise":"05:51","Sunset":"19:47"}}
03:41:41.311 RSL: STATUS10 = {"StatusSNS":{"Time":"2026-04-19T03:41:41"}}
03:41:41.314 RSL: STATUS11 = {"StatusSTS":{"Time":"2026-04-19T03:41:41","Uptime":"0T00:31:29","UptimeSec":1889,"Heap":238,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":0,"Berry":{"HeapUsed":3,"Objects":47},"POWER":"ON","Dimmer":26,"Color":"004209","HSBColor":"128,100,26","Channel":[0,26,3],"Scheme":0,"Width":1,"Fade":"OFF","Speed":1,"LedTable":"ON","Wifi":{"AP":1,"SSId":"Maria Home","BSSId":"26:E8:29:E1:1F:30","Channel":11,"Mode":"HT20","RSSI":100,"Signal":-48,"LinkCount":1,"Downtime":"0T00:00:03"},"Hostname":"tasmota-mikrofon1","IPAddress":"10.13.9.208"}}
  • Set weblog to 4 and then, when you experience your issue, provide the output of the Console log:
  Console output here

[i2srec2.log](https://github.com/user-attachments/files/26863706/i2srec2.log)

:
03:45:11.971 CMD: i2srec2 /test2.opus
03:45:11.971 SRC: WebConsole from 10.13.10.23
03:45:11.972 CMD: Grp 0, Cmd 'I2SREC', Idx 2, Len 11, Pld -99, Data '/test2.opus'
03:45:11.972 I2S: start OPUS encoding: 16000 Hz
03:45:11.972 I2S: SetRxRate: 16000 was 16000 hertz=16000 rx_running=0
03:45:11.972 I2S: startRx called
03:45:11.973 I2S: mic init rx_channels:1 rx_running:0 rx_handle:0x3fcb06ac
03:45:11.973 I2S: (duplex) TX channel enable for RX clocks err:0x0000
03:45:11.973 I2S: RX channel enable err:0x0000
03:45:11.975 I2S: samples 320, bytesize 640, time: 20
03:45:11.976 RSL: RESULT = {"I2SRec":"/test2.opus"}
03:45:11.976 _mic: 0 , 0, 0
03:45:12.004 _mic: 7 , 0, 480
03:45:12.021 _mic: 5 , 0, 480
03:45:12.041 _mic: 6 , 0, 640
03:45:12.060 _mic: 5 , 0, 640
03:45:12.080 _mic: 5 , 0, 640
[.....]
03:45:42.080 _mic: 5 , 0, 640
03:45:42.100 _mic: 5 , 0, 640
03:45:42.120 _mic: 5 , 0, 640
03:45:42.140 _mic: 5 , 0, 640
03:45:42.167 _mic: 12 , -1, 640
03:45:42.189 I2S: calling stopRx() rx_running:1 rx_handle:0x3fcb06ac
03:45:42.190 I2S: stopRx i2s_channel_disable err=0x0000
03:45:42.191 I2S: calling stopTx() tx_running:1 tx_handle:0x3fcb0508
03:45:42.192 I2S: stopTx i2s_channel_disable err=0x0000
03:45:42.193 I2S: (duplex) TX also stopped after RX stopped
03:45:42.194 I2S: record task result code: 0, min bytes stack free: 58368

TO REPRODUCE

  1. Compile Tasmota with i2s, mp3, opus and PSRAM
  2. Record audio from console using "i2srec2 /test.opus"
  3. Wait for 30 Seconds, observe console
  4. Recording stops

EXPECTED BEHAVIOUR

I expect the recording to continue until i stop it. There does not seem to be a mantion of a limitation of the recording length in the documentation, in the code etc.

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

I am not overly experienced with code, but i tried to trace back where StopRX is called.
It happens in xdrv_42_1_i2s_mp3mic_idf51.ino:343, exactly when "written" jumps to -1:
__enctime = millis();
if(bytes_read != 0){
written = mic_enc->encode(bytes_read >> 1); //transmit samples, written is an error code
}
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("_mic: %u , %i, %i"), millis() - __enctime, written, bytes_read);
if(written < 0){
break;
}

The file is written to FlashFS or SDCard after the recording stops, and contains 30 seconds of valid Audio.

(Please, remember to close the issue when the problem has been addressed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugType - Confirmated BugfixedResult - The work on the issue has ended

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions