用 ALSA 指令,放音或錄音
可以內建 default audio device bcm2835 ALSA 的音效。
如果用 USB sound card 音效卡,ALSA 指令包括: aplay, arecord, amixer, alsamixer, alsaloop, alsactl, speaker-test, etc.
Test USB Audio Device
speaker-test -Dplughw:CARD=Device -c2 -twav
參數 -D option 選擇 plughw:CARD=Device,
參數 -c2 is the left and right channel, 選擇左右聲道
參數 -twav selects to play the .wav sound file. 選擇 wav 檔
指令 arecord for audio capture, 可錄音
指令 aplay to capture audio playback. 可播音
參數 -f option sets the audio format, 是音效檔格式
** 安裝 pygame 支援 音效卡 **
sudo apt-get update
sudo apt-get install python3-pygame
import pygame
pygame.mixer.init()
pygame.mixer.music.load("myFile.wav")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue
發現滿好用的!
(不用) * 安裝 PyAudio 支援 音效卡 較早的硬體如 3B,可能播放音效會斷續!
Python 程式中使用 PyAudio
Example: Blocking Mode Audio I/O
以上為 python 範例
How to uninstall or remove python-pyaudio software package
** 有關 time 的用法 **
time.strftime()
result: 可以輸出指定的日期或時間字串:
Directive | Meaning | Notes |
---|---|---|
| Locale’s abbreviated weekday name. | |
| Locale’s full weekday name. | |
| Locale’s abbreviated month name. | |
| Locale’s full month name. | |
| Locale’s appropriate date and time representation. | |
| Day of the month as a decimal number [01,31]. | |
| Hour (24-hour clock) as a decimal number [00,23]. | |
| Hour (12-hour clock) as a decimal number [01,12]. | |
| Day of the year as a decimal number [001,366]. | |
| Month as a decimal number [01,12]. | |
| Minute as a decimal number [00,59]. | |
| Locale’s equivalent of either AM or PM. | (1) |
| Second as a decimal number [00,61]. | (2) |
| Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. | (3) |
| Weekday as a decimal number [0(Sunday),6]. | |
| Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0. | (3) |
| Locale’s appropriate date representation. | |
| Locale’s appropriate time representation. | |
| Year without century as a decimal number [00,99]. | |
| Year with century as a decimal number. | |
| Time zone offset indicating a positive or negative time difference from UTC/GMT of the form +HHMM or -HHMM, where H represents decimal hour digits and M represents decimal minute digits [-23:59, +23:59]. | |
| Time zone name (no characters if no time zone exists). | |
| A literal |
沒有留言:
張貼留言