본문으로 바로가기

라즈베리 파이에서 audio file 실행하기

category Senior Project/Notes 2022. 1. 22. 00:31

| 에러

os.system("start ./TTS_file.mp3")

os 는 윈도우 환경에서만 쓸 수 있는 라이브러리이기 때문에 오류가 발생했다.

 

| 해결

import pygame

pygame.mixer.init()
pygame.mixer.music.load("./file.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
    continue

따른ㅆ 환경에서 오디오 파일을 재생하기 위한 널리 알려진 방법은 pygame 라이브러리를 사용하는 것이다. 

라즈베리 파이에서도 정상 작동 하였다.