Skip to content

Commit cc5d724

Browse files
committed
Support ogg files frame duration <= 60
1 parent bba26ef commit cc5d724

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

main/audio/audio_service.cc

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ void AudioService::PlaySound(const std::string_view& ogg) {
554554
bool seen_head = false;
555555
bool seen_tags = false;
556556
int sample_rate = 16000; // 默认值
557-
int frame_duration = OPUS_FRAME_DURATION_MS; // 默认值
558557

559558
while (true) {
560559
size_t pos = find_page(offset);
@@ -595,15 +594,8 @@ void AudioService::PlaySound(const std::string_view& ogg) {
595594
if (pkt_len >= 19 && std::memcmp(pkt_ptr, "OpusHead", 8) == 0) {
596595
seen_head = true;
597596

598-
// OpusHead结构:
599-
// 0-7: "OpusHead"
600-
// 8: version (1)
601-
// 9: channel_count
602-
// 10-11: pre_skip (little-endian)
603-
// 12-15: input_sample_rate (little-endian)
604-
// 16-17: output_gain (little-endian)
605-
// 18: mapping_family
606-
597+
// OpusHead结构:[0-7] "OpusHead", [8] version, [9] channel_count, [10-11] pre_skip
598+
// [12-15] input_sample_rate, [16-17] output_gain, [18] mapping_family
607599
if (pkt_len >= 12) {
608600
uint8_t version = pkt_ptr[8];
609601
uint8_t channel_count = pkt_ptr[9];
@@ -612,18 +604,8 @@ void AudioService::PlaySound(const std::string_view& ogg) {
612604
// 读取输入采样率 (little-endian)
613605
sample_rate = pkt_ptr[12] | (pkt_ptr[13] << 8) |
614606
(pkt_ptr[14] << 16) | (pkt_ptr[15] << 24);
615-
616607
ESP_LOGI(TAG, "OpusHead: version=%d, channels=%d, sample_rate=%d",
617608
version, channel_count, sample_rate);
618-
619-
// 根据采样率推断可能的帧持续时间
620-
if (sample_rate == 48000) {
621-
frame_duration = 20;
622-
} else if (sample_rate == 16000) {
623-
frame_duration = 60;
624-
} else {
625-
frame_duration = OPUS_FRAME_DURATION_MS; // 保持默认值
626-
}
627609
}
628610
}
629611
}
@@ -640,7 +622,7 @@ void AudioService::PlaySound(const std::string_view& ogg) {
640622
// Audio packet (Opus)
641623
auto packet = std::make_unique<AudioStreamPacket>();
642624
packet->sample_rate = sample_rate;
643-
packet->frame_duration = frame_duration;
625+
packet->frame_duration = 60;
644626
packet->payload.resize(pkt_len);
645627
std::memcpy(packet->payload.data(), pkt_ptr, pkt_len);
646628
PushPacketToDecodeQueue(std::move(packet), true);

main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
espressif/esp_lcd_panel_io_additions: ^1.0.1
1515
78/esp_lcd_nv3023: ~1.0.0
1616
78/esp-wifi-connect: ~2.5.0
17-
78/esp-opus-encoder: ~2.4.0
17+
78/esp-opus-encoder: ~2.4.1
1818
78/esp-ml307: ~3.2.6
1919
78/xiaozhi-fonts: ~1.4.0
2020
espressif/led_strip: ^2.5.5

0 commit comments

Comments
 (0)