我正在使用人类语音创建人类认证系统。
因此,系统将具有一个保存人类语音的目录,并将其与当前语音进行比较。
经过比较,它应该能够识别该人。我不知道是否可能。
目前,我能够做到以下几点:
代码:
import speech_recognition as sr
import numpy as np
import matplotlib.pyplot as plt
from scipy.io import wavfile
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
with open("./a_1.wav","wb") as f:
f.write(audio.get_wav_data())
try:
a = r.recognize_google(audio)
print(a)
except LookupError:
print("Could not understand audio")
frequency_sampling, audio_signal = wavfile.read("./a_1.wav")
print('Signal shape:', audio_signal.shape)
print('Signal Datatype:', audio_signal.dtype)
print('Signal duration:', round(audio_signal.shape[0] /
float(frequency_sampling), 2), 'seconds')
audio_signal = audio_signal / np.power(2, 15)
length_signal = len(audio_signal)
half_length = np.ceil((length_signal + 1) / 2.0).astype(np.int)
signal_frequency = np.fft.fft(audio_signal)
signal_frequency = abs(signal_frequency[0:half_length]) / length_signal
signal_frequency **= 2
len_fts = len(signal_frequency)
if length_signal % 2:
signal_frequency[1:len_fts] *= 2
else:
signal_frequency[1:len_fts-1] *= 2
signal_power = 10 * np.log10(signal_frequency)
x_axis = np.arange(0, half_length, 1) * (frequency_sampling / length_signal) / 1000.0
plt.figure()
plt.plot(x_axis, signal_power, color='black')
plt.xlabel('Frequency (kHz)')
plt.ylabel('Signal power (dB)')
plt.show()
plt.plot(time_axis, audio_signal, color='blue')
plt.xlabel('Time (milliseconds)')
plt.ylabel('Amplitude')
plt.title('Input audio signal')
plt.show()
为了进行语音比较,我尝试了:
import audiodiff
print audiodiff.audio_equal('a_1.wav', 'a_2.wav', ffmpeg_bin=None)
# false
任何人都可以帮助我进行语音人工身份验证。