일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- pandas
- Converting
- docker
- judge
- numpy
- Laravel
- Paper
- KAKAO
- Flask
- CUDA
- git
- Linux
- format
- Container
- Database
- LLM
- AI
- GitLab
- pytorch
- file
- Python
- Package
- TORCH
- enV
- Windows
- list
- DB
- evaluation
- PostgreSQL
- Mac
Archives
- Today
- Total
Daily Develope
[Python] PCM 음성파일 파형 출력 (with pyplot) 본문
ㅇ 사용 라이브러리
- numpy : pcm파일 로딩
- librosa : pcm파일을 wav형태로 변환
- matplotlib : 파형 출력
ㅇ 코드
import numpy as np
import librosa as lr
import matplotlib.pyplot as plt
### Load File
target = "pcm파일경로"
f=open(target, 'rb')
buf = bytearray(f.read())
pcm_data = np.frombuffer(buf, dtype = 'int16') # bit 수에 맞게 입력
wav_data = lr.util.buf_to_float(x=pcm_data, n_bytes=2)
### Draw Graph
x_axis = [i/8000 if i>0 else i for i in range(0, len(wav_data))] # sampling rate에 맞게 x축 시간값 저장
plt.figure()
plt.plot(x_axis, wav_data) # x축은 x_axis, y축은 wav_data 사용
plt.show()
'Develope > Python' 카테고리의 다른 글
[Python] MFCC 구현 (0) | 2022.04.04 |
---|---|
[Python] config 환경설정 관리 및 사용 (0) | 2022.03.31 |
[Python] PCM 파일 통합 및 WAV로 변환 (0) | 2022.02.15 |
[Python] 매칭 (문자열 / 리스트 / 정규식) (0) | 2022.01.15 |
[Python] 로그, 로깅 (logging) (0) | 2022.01.15 |
Comments