@@ -554,7 +554,6 @@ void AudioService::PlaySound(const std::string_view& ogg) {
554
554
bool seen_head = false ;
555
555
bool seen_tags = false ;
556
556
int sample_rate = 16000 ; // 默认值
557
- int frame_duration = OPUS_FRAME_DURATION_MS; // 默认值
558
557
559
558
while (true ) {
560
559
size_t pos = find_page (offset);
@@ -595,15 +594,8 @@ void AudioService::PlaySound(const std::string_view& ogg) {
595
594
if (pkt_len >= 19 && std::memcmp (pkt_ptr, " OpusHead" , 8 ) == 0 ) {
596
595
seen_head = true ;
597
596
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
607
599
if (pkt_len >= 12 ) {
608
600
uint8_t version = pkt_ptr[8 ];
609
601
uint8_t channel_count = pkt_ptr[9 ];
@@ -612,18 +604,8 @@ void AudioService::PlaySound(const std::string_view& ogg) {
612
604
// 读取输入采样率 (little-endian)
613
605
sample_rate = pkt_ptr[12 ] | (pkt_ptr[13 ] << 8 ) |
614
606
(pkt_ptr[14 ] << 16 ) | (pkt_ptr[15 ] << 24 );
615
-
616
607
ESP_LOGI (TAG, " OpusHead: version=%d, channels=%d, sample_rate=%d" ,
617
608
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
- }
627
609
}
628
610
}
629
611
}
@@ -640,7 +622,7 @@ void AudioService::PlaySound(const std::string_view& ogg) {
640
622
// Audio packet (Opus)
641
623
auto packet = std::make_unique<AudioStreamPacket>();
642
624
packet->sample_rate = sample_rate;
643
- packet->frame_duration = frame_duration ;
625
+ packet->frame_duration = 60 ;
644
626
packet->payload .resize (pkt_len);
645
627
std::memcpy (packet->payload .data (), pkt_ptr, pkt_len);
646
628
PushPacketToDecodeQueue (std::move (packet), true );
0 commit comments