sndhdr — 음향 파일 유형 판단¶
소스 코드: Lib/sndhdr.py
Deprecated since version 3.11, will be removed in version 3.13: The sndhdr module is deprecated
(see PEP 594 for details and alternatives).
sndhdr은 파일에 있는 음향 데이터 유형을 판별하려고 하는 유틸리티 함수를 제공합니다. 이 함수는 파일에 저장된 음향 데이터의 형식을 결정할 수 있을 때 5가지 어트리뷰트를 포함하는 namedtuple()을 반환합니다: (filetype, framerate, nchannels, nframes, sampwidth). type의 값은 데이터 유형을 나타내며 'aifc', 'aiff', 'au', 'hcom', 'sndr', 'sndt', 'voc', 'wav', '8svx', 'sb', 'ub' 또는 'ul' 문자열 중 하나가 됩니다. sampling_rate는 실제 값이거나 알 수 없거나 디코드하기 어려우면 0입니다. 마찬가지로, channels는 채널 수거나 결정할 수 없거나 값을 디코드하기 어려우면 0이 됩니다. frames 의 값은 프레임 수 또는 -1이 됩니다. 튜플의 마지막 항목인 bits_per_sample는 비트 단위의 샘플 크기이거나 A-LAW의 경우 'A' 또는 u-LAW의 경우 'U' 입니다.
- sndhdr.what(filename)¶
whathdr()를 사용하여 filename 파일에 저장된 음향 데이터 유형을 판단합니다. 성공하면 위의 설명과 같이 네임드 튜플을 반환합니다. 그렇지 않으면None을 반환합니다.버전 3.5에서 변경: 결과가 튜플에서 네임드 튜플로 변경되었습니다.
- sndhdr.whathdr(filename)¶
파일 헤더에 따라 파일에 저장된 음향 데이터의 유형을 판단합니다. 파일의 이름은 filename으로 주어집니다. 이 함수는 성공 시에 위에서 설명한 네임드 튜플을 반환하고, 그렇지 않으면
None을 반환합니다.버전 3.5에서 변경: 결과가 튜플에서 네임드 튜플로 변경되었습니다.
The following sound header types are recognized, as listed below with the return value
from whathdr(): and what():
Value |
Sound header format |
|---|---|
|
Compressed Audio Interchange Files |
|
Audio Interchange Files |
|
Au Files |
|
HCOM Files |
|
Sndtool Sound Files |
|
Creative Labs Audio Files |
|
Waveform Audio File Format Files |
|
8-Bit Sampled Voice Files |
|
Signed Byte Audio Data Files |
|
UB Files |
|
uLAW Audio Files |
- sndhdr.tests¶
A list of functions performing the individual tests. Each function takes two arguments: the byte-stream and an open file-like object. When
what()is called with a byte-stream, the file-like object will beNone.The test function should return a string describing the image type if the test succeeded, or
Noneif it failed.
Example:
>>> import sndhdr
>>> imghdr.what('bass.wav')
'wav'
>>> imghdr.whathdr('bass.wav')
'wav'