(wav: bytes)
| 88 | |
| 89 | |
| 90 | def extract_pcm_from_wav(wav: bytes) -> bytes: |
| 91 | data = wav |
| 92 | sample_rate = None |
| 93 | if len(data) > 44: |
| 94 | frame_len = 44 |
| 95 | file_len = len(data) |
| 96 | try: |
| 97 | header_fields = {} |
| 98 | header_fields['ChunkID'] = str(data[0:4], 'UTF-8') |
| 99 | header_fields['Format'] = str(data[8:12], 'UTF-8') |
| 100 | header_fields['Subchunk1ID'] = str(data[12:16], 'UTF-8') |
| 101 | if header_fields['ChunkID'] == 'RIFF' and header_fields[ |
| 102 | 'Format'] == 'WAVE' and header_fields[ |
| 103 | 'Subchunk1ID'] == 'fmt ': |
| 104 | header_fields['SubChunk1Size'] = struct.unpack( |
| 105 | '<I', data[16:20])[0] |
| 106 | header_fields['SampleRate'] = struct.unpack('<I', |
| 107 | data[24:28])[0] |
| 108 | sample_rate = header_fields['SampleRate'] |
| 109 | |
| 110 | if header_fields['SubChunk1Size'] == 16: |
| 111 | frame_len = 44 |
| 112 | elif header_fields['SubChunk1Size'] == 18: |
| 113 | frame_len = 46 |
| 114 | else: |
| 115 | return data, sample_rate |
| 116 | |
| 117 | data = wav[frame_len:file_len] |
| 118 | except Exception: |
| 119 | # no treatment |
| 120 | pass |
| 121 | |
| 122 | return data, sample_rate |
| 123 | |
| 124 | |
| 125 | def expect_token_number(instr, token): |
no outgoing calls
no test coverage detected
searching dependent graphs…