Python 的口語語言處理
Daniel Bourke
Machine Learning Engineer/YouTube Creator
# 匯入音訊檔
wav_file = AudioSegment.from_file("wav_file.wav")
# 降低 60 dB
quiet_wav_file = wav_file - 60
# 嘗試辨識小聲音訊
recognizer.recognize_google(quiet_wav_file)
UnknownValueError:
# 提高音量 10 dB
louder_wav_file = wav_file + 10
# 嘗試辨識
recognizer.recognize_google(louder_wav_file)
this is a wav file
# 匯入 AudioSegment 並正規化
from pydub import AudioSegment
from pydub.effects import normalize
from pydub.playback import play
# 匯入忽大忽小的音訊
loud_quiet = AudioSegment.from_file("loud_quiet.wav")
# 正規化音量
normalized_loud_quiet = normalize(loud_quiet)
# 播放檢查
play(normalized_loud_quiet)
# 匯入開頭有雜訊的音訊
static_at_start = AudioSegment.from_file("static_at_start.wav")
# 以切片移除雜訊
no_static_at_start = static_at_start[5000:]
# 檢查新音訊
play(no_static_at_start)
# 匯入兩個音訊檔
wav_file_1 = AudioSegment.from_file("wav_file_1.wav")
wav_file_2 = AudioSegment.from_file("wav_file_2.wav")
# 合併兩個音訊檔
wav_file_3 = wav_file_1 + wav_file_2
# 播放檢查
play(wav_file_3)
# 合併兩個 wav 並放大音量
louder_wav_file_3 = wav_file_1 + wav_file_2 + 10
# 匯入電話錄音
phone_call = AudioSegment.from_file("phone_call.wav")
# 查詢聲道數
phone_call.channels
2
# 立體聲切成單聲道
phone_call_channels = phone_call.split_to_mono()
phone_call_channels
[<pydub.audio_segment.AudioSegment, <pydub.audio_segment.AudioSegment>]
# 取得清單第一個項目的聲道數
phone_call_channels[0].channels
1
# 辨識第一個聲道
recognizer.recognize_google(phone_call_channel_1)
the pydub library is really useful
Python 的口語語言處理