end

‫‪In the name of God‬‬
‫استاد ارجمند جناب آقای دکتر راحتی قوچانی‬
‫دانشجویان‪:‬‬
‫میثم برادران‬
‫رضا مرادیان‬
‫آذر ‪93‬‬
‫‪1‬‬
Subject: An
Automatic Speaker Recognition System
1 Overview
Speaker recognition is the process of automatically recognizing who is speaking on
the basis of individual information included in speech waves. This technique makes it
possible to use the speaker's voice to verify their identity and control access to services
such as voice dialing, banking by telephone, telephone shopping, database access
services, information services, voice mail, security control for confidential information
areas, and remote access to computers.
This document describes how to build a simple, yet complete and representative
automatic speaker recognition system.Such a speaker recognition system has potential in
many security applications. For example, users have to speak a PIN (Personal
Identification Number) in order to gain access to the laboratory door, or users have to
speak their credit card number over the telephone line to verify their identity. By
checking the voice characteristics of the input utterance, using an automatic speaker
recognition system similar to the one that we will describe, the system is able to add an
extra level of security.
2 Principles of Speaker Recognition
Speaker recognition can be classified into identification and verification. Speaker
identification is the process of determining which registered speaker provides a given
utterance. Speaker verification,on the other hand, is the process of accepting or rejecting
the identity claim of a speaker. Figure 1 shows the basic structures of speaker
identification and verification systems. The system that we will describe is classified as
text-independent speaker identification system since its task is to identify the person who
speaks regardless of what is saying.
At the highest level, all speaker recognition systems contain two main modules(refer
to Figure 1): feature extraction and feature matching. Feature extraction is the
processthat extracts a small amount of data from the voice signal that can later be used to
represent each speaker. Feature matching involvesthe actual procedure to identify the
unknown speaker by comparing extracted features from his/her voice input with the ones
from a set of known speakers.We will discuss each module in detail in later sections.
2
(a) Speaker identification
(b) Speaker verification
Figure 1. Basic structures of speaker recognition systems
All speaker recognition systems have toserve two distinguished phases. The first one
is referred to the enrolment or training phase, while the second one is referred to as the
operational or testing phase. In the training phase, each registered speakerhas to provide
samples of their speech so that the system can build or train a reference model for that
speaker. In case of speaker verification systems, in addition, a speaker-specific threshold
is also computed from the training samples.In the testing phase, the input speech is
matched with stored reference model(s) and a recognition decision is made.
Speaker recognition is a difficult task. Automatic speaker recognition works based
on the premise that a person’s speech exhibits characteristics that are unique to the
speaker. However this task has been challenged by the highly variant of input speech
signals. The principle source of variance is the speaker himself/herself. Speech signals
in training and testing sessions can be greatly differentdue to many facts such as people
voice change with time, health conditions (e.g. the speaker has a cold), speaking rates,
and so on. There are also other factors, beyond speaker variability, that present a
3
challenge to speaker recognition technology. Examples of these are acoustical noise and
variations in recording environments (e.g. speaker uses different telephone handsets).
3 Speech Feature Extraction
3.1
Introduction
The purpose of this module is to convert the speech waveform, using digital signal
processing (DSP) tools, to a set of features (at a considerably lower information rate) for
further analysis. This is often referred as the signal-processing front end.
The speech signal is a slowly timed varying signal (it is called quasi-stationary).An
example of speech signal is shown in Figure 2.When examined over a sufficiently short
period of time (between 5 and 100 msec), its characteristics are fairly stationary.
However, over long periods of time (on the order of 1/5 seconds or more) the signal
characteristic change to reflect the different speech sounds being spoken. Therefore,
short-time spectral analysis is the most common way to characterize the speech signal.
Figure 2. Example of speech signal
A wide range of possibilities exist for parametrically representing the speech signal
for the speaker recognition task, such as Linear Prediction Coding (LPC),Mel-Frequency
Cepstrum Coefficients (MFCC), and others. MFCC is perhaps the best known and most
popular, and will be described in this paper.
MFCC’s are based on the known variation of the human ear’s critical bandwidths
with frequency, filters spaced linearly at low frequencies and logarithmically at high
frequencies have been used to capture the phonetically important characteristics of
4
speech. This is expressed in the mel-frequency scale, which is a linear frequency spacing
below 1000 Hz and a logarithmic spacing above 1000 Hz. The process of computing
MFCCs is described in more detail next.
3.2
Mel-frequency cepstrum coefficients processor
A block diagram of the structure of an MFCC processor is given in Figure 3. The
speech input istypically recorded at a sampling rate above 10000 Hz. This sampling
frequency was chosen to minimize the effects of aliasing in the analog-to-digital
conversion.These sampled signals can capture all frequencies up to 5 kHz, which cover
most energy of sounds that are generated by humans. As been discussed previously, the
main purpose of the MFCC processor isto mimic the behavior of the human ears. In
addition, rather than the speech waveforms themselves, MFFC’s are shown to be less
susceptible to mentioned variations.
Figure 3. Block diagram of the MFCC processor
3.2.1 Frame Blocking
In this step thecontinuous speech signal is blocked into frames of N samples, with
adjacent frames being separated by M (M < N).The first frame consists of the first N
samples.The second framebegins M samples after the first frame, and overlaps it by N M samples and so on. This process continues until all the speech is accounted for within
one or more frames. Typical values for N and M are N = 256 (which is equivalent to ~ 30
msec windowing and facilitate the fast radix-2 FFT) and M = 100.
3.2.2 Windowing
The next step in the processing is to window each individual frame so as to minimize
the signal discontinuities at the beginning and end of each frame. The concept here is to
minimize the spectral distortion by using the window to taper the signal to zero at the
beginning and end of each frame. If we define the window as
, where
N is the number of samples in each frame, then the result of windowing is the signal
5
Typically the Hamming window is used, which has the form:
3.2.3 Fast Fourier Transform (FFT)
The next processing step is the Fast Fourier Transform, which converts each frame of
N samples from the time domain into the frequency domain. The FFT is a fast algorithm
to implement the Discrete Fourier Transform (DFT), which is defined on the set of
Nsamples {xn}, as follow:
In general Xk’s are complex numbers and we only consider their absolute values
(frequency magnitudes). The resulting sequence {Xk} is interpreted as follow:positive
frequencies
frequencies
sampling frequency.
correspond to values
correspond to
, while negative
. Here, Fsdenotes the
The result after this step is often referred to as spectrum or periodogram.
3.2.4 Mel-frequency Wrapping
As mentioned above, psychophysical studies have shown that human perception of
the frequency contents of sounds for speech signals does not follow a linear scale. Thus
for each tone with an actual frequency, f, measured in Hz, a subjective pitch is measured
on a scale called the ‘mel’ scale. The mel-frequency scale is a linear frequency spacing
below 1000 Hz and a logarithmic spacing above 1000 Hz.
6
Figure 4. An example of mel-spaced filterbank
One approach to simulating the subjective spectrum is to use a filter bank, spaced
uniformly on the mel-scale (see Figure 4).That filter bank has a triangular bandpass
frequency response, and the spacing as well as the bandwidth is determined by a constant
mel frequency interval. The number of mel spectrum coefficients, K, is typically chosen
as 20. Note that this filter bank is applied in the frequency domain, thus it simply
amounts to applying the triangle-shape windows as in the Figure 4 to the spectrum. A
useful way of thinking about this mel-wrapping filter bank is to view each filter as a
histogram bin (where bins have overlap) in the frequency domain.
3.2.5 Cepstrum
In this final step, we convert the log mel spectrum back to time. The result is called
the mel frequency cepstrum coefficients (MFCC). The cepstral representation of the
speech spectrum provides a good representation of the local spectral properties of the
signal for the given frame analysis.Because the mel spectrum coefficients (and so their
logarithm) are real numbers, we can convert them to the time domain using the Discrete
Cosine Transform (DCT).Therefore if we denote those mel power spectrum
7
coefficientsthat are the result of the last step are
MFCC's,
, we can calculate the
as
Note that we exclude the first component,
from the DCT since it represents the
mean value of the input signal, which carried little speaker specific information.
3.3
Summary
By applying the procedure described above, for each speech frame of around 30msec
with overlap, a set of mel-frequency cepstrum coefficients is computed. These are result
of a cosine transform of the logarithm of the short-term power spectrum expressed on a
mel-frequency scale.This set of coefficients is called an acoustic vector. Therefore each
input utterance is transformed into a sequence of acoustic vectors. In the next section we
will see how those acoustic vectors can be used to represent and recognize the voice
characteristic of the speaker.
4 Feature Matching
4.1
Overview
The problem of speaker recognition belongs to a much broader topic in scientific and
engineering so called pattern recognition. The goal of pattern recognition is to classify
objects of interest into one of a number of categories or classes.The objects of interest are
generically called patterns and in our case are sequences of acoustic vectors that are
extracted from an input speech using the techniques described in the previous section.
The classes here refer to individual speakers. Since the classification procedure in our
case is applied on extracted features, it can be also referred to as feature matching.
Furthermore, if there exists some set of patterns that the individual classes of which
are already known, then one has a problem in supervised pattern recognition. These
patterns comprise the training set and are used to derive a classification algorithm. The
remaining patterns are then used to test the classification algorithm; these patterns are
collectively referred to as the test set. If the correct classes of the individual patterns in
the test set are also known, then one can evaluate the performance of the algorithm.
The state-of-the-art in feature matching techniques used in speaker recognition
include Dynamic Time Warping (DTW), Hidden Markov Modeling (HMM), and Vector
Quantization (VQ). In this project, the VQ approach will be used, due to ease of
implementation and high accuracy.VQ is a process of mapping vectors from a large
8
vector space to a finite number of regions in that space.Each region is called a cluster and
can be represented by its center called a codeword. The collection of all codewords is
called a codebook.
Figure 5 shows a conceptual diagram to illustrate this recognition process. In the
figure, only two speakers and two dimensions of the acoustic space are shown.The circles
refer to the acoustic vectors from the speaker 1 while the triangles are from the speaker 2.
In the training phase, using the clustering algorithm described in Section 4.2, a speakerspecific VQ codebook is generated for each known speaker by clustering his/her training
acoustic vectors. The result codewords (centroids) are shown in Figure 5 by black circles
and black triangles for speaker 1 and 2, respectively. The distance from a vector to the
closest codeword of a codebook is called a VQ-distortion.In the recognition phase, an
input utterance of an unknown voice is “vector-quantized” using each trained codebook
and the total VQ distortion is computed. The speaker corresponding to the VQ codebook
with smallest total distortion is identified as the speaker of the input utterance.
Figure 5.Conceptual diagram illustrating vector quantization codebook formation.
One speaker can be discriminated from another based of the location of centroids.
(Adapted from Song et al., 1987)
4.2
Clustering the Training Vectors
After the enrolment session, the acoustic vectors extracted from input speech of each
speaker provide a set of training vectors for that speaker. As described above, the next
important step is to build a speaker-specific VQ codebook for each speaker using those
training vectors.There is a well-know algorithm, namely LBG algorithm [Linde, Buzoand
Gray, 1980], for clustering a set of L training vectors into a set of M codebook vectors.
The algorithm is formally implemented by the following recursive procedure:
9
Design a 1-vector codebook; this is the centroid of the entire set of training vectors
(hence, no iteration is required here).
2. Double the size of the codebook by splitting each current codebook yn according to
the rule
1.
wheren varies from 1 to the current size of the codebook, and
parameter (we choose =0.01).
is a splitting
3.
Nearest-Neighbor Search: for each training vector, find the codeword in the current
codebook that is closest (in terms of similarity measurement), and assign that vector
to the corresponding cell (associated with the closest codeword).
4.
Centroid Update: update the codeword in each cell using the centroid of the training
vectors assigned to that cell.
5.
Iteration 1: repeat steps 3 and 4 until the average distance falls below a preset
threshold
6.
Iteration 2: repeat steps 2, 3 and 4 until a codebook size of M is designed.
Intuitively, the LBG algorithm designs an M-vector codebook in stages. It starts first
by designing a 1-vector codebook, then uses a splitting technique on the codewords to
initialize the search for a 2-vector codebook, and continues the splitting process until the
desired M-vector codebook is obtained.
Figure 6 shows, in a flow diagram, the detailed steps of the LBG algorithm. “Cluster
vectors” is the nearest-neighbor search procedure which assigns each training vector to a
cluster associated with the closest codeword. “Find centroids” is the centroid update
procedure. “Compute D (distortion)” sums the distances of all training vectors in the
nearest-neighbor search so as to determine whether the procedure has converged.
10
Figure 6. Flow diagram of the LBG algorithm (Adapted from Rabiner and Juang, 1993)
5 Project
As stated before, in this project we will experiment with the building and testing of an
automatic speaker recognition system. In order to build such a system, one have to go
through the steps that were described in previous sections.The most convenient platform
for this is the Matlab environment since many of the above tasks were already
implemented in Matlab. The project Web page given at the beginning provides a test
database and several helper functions to ease the development process.We supplied you
with two utility functions: melfb and disteu; and two main functions: train and
test.Download all of these files from the project Web page into your working
folder.The first two files can be treated as a black box, but the later two needs to be
thoroughly understood. In fact, your tasks are to write two missing functions: mfcc and
vqlbg, which will be called from the given main functions. In order to accomplish that,
follow each step in this section carefully and check your understanding by answering all
the questions.
11
5.1
Speech Data
Down load the ZIP file of the speech database from the project Web page. After
unzipping the file correctly, you will find two folders, TRAIN and TEST, each contains 8
files, named: S1.WAV, S2.WAV, …, S8.WAV; each is labeled after the ID of the
speaker. These files were recorded in Microsoft WAV format. In Windows systems, you
can listen to the recorded sounds by double clicking into the files.
Our goal is to train a voice model (or more specific, a VQ codebook in the MFCC
vector space) for each speaker S1 - S8 using the corresponding sound file in the TRAIN
folder.After this training step, the system would have knowledge of the voice
characteristic of each (known) speaker. Next, in the testing phase, the system will be
able to identify the (assumed unknown) speaker of each sound file in the TEST folder.
Question 1: Play each sound file in the TRAIN folder. Can you distinguish the voices
of the eight speakers in the database? Now play each sound in the TEST folder in a
random order without looking at the file name (pretending that you do not known the
speaker) and try to identify the speaker using your knowledge of their voices that you just
learned from the TRAIN folder. This is exactly what the computer will do in our system.
What is your (human performance) recognition rate? Record this result so that it could
be later on compared against the computer performance of our system.
5.2
Speech Processing
In this phase you are required to write a Matlab function that reads a sound file and
turns it into a sequence of MFCC (acoustic vectors) using the speech processing steps
described previously. Many of those tasks are already provided by either standard or our
supplied Matlab functions. The Matlab functions that you would need are: wavread,
hamming, fft, dct and melfb (supplied function). Type helpfunction_name at
the Matlab prompt for more information about these functions.
Question 2: Read a sound file into Matlab. Check it by playing the sound file in Matlab
using the function: sound. What is the sampling rate? What is the highest frequency
that the recorded sound can capture with fidelity? With that sampling rate, how many
msecs of actual speech are contained in a block of 256 samples?
Plot the signal to view it in the time domain.It should be obvious that the raw data in
the time domain has a very high amount of data and it is difficult for analyzing the voice
characteristic. So the motivation for this step (speech feature extraction) should be clear
now!
Now cut the speech signal (a vector) into frames with overlap (refer to the frame
section in the theory part).The result is a matrix where each column is a frame of N
samples from original speech signal.Applying the steps “Windowing” and “FFT” to
transform the signal into the frequency domain. This process is used in many different
applications and is referred in literature as Windowed Fourier Transform (WFT) or Short-
12
Time Fourier Transform (STFT). The result is often called as the spectrum or
periodogram.
Question 3:After successfully running the preceding process, what is the
interpretation of the result?Compute the power spectrum and plot it out using the
imagesc command. Note that it is better to view the power spectrum on the log scale.
Locate the region in the plot that contains most of the energy. Translate this location
into the actual ranges in time (msec) and frequency (in Hz) of the input speech signal.
Question 4: Compute and plot the power spectrum of a speech file using different
frame size: for example N = 128, 256 and 512. In each case, set the frame increment M
to be about N/3. Can you describe and explain the differences among those spectra?
The last step in speech processing is converting the power spectrum into melfrequency cepstrum coefficients. The supplied function melfb facilitates this task.
Question 5: Type help melfb at the Matlab prompt for more information about
this function. Follow the guidelines to plot out the mel-spaced filter bank. What is the
behavior of this filter bank? Compare it with the theoretical part.
Question 6: Compute and plot the spectrum of a speech file before and after the melfrequency wrapping step. Describe and explain the impact of the melfb program.
Finally, complete the “Cepstrum” step and put all pieces together into a single Matlab
function, mfcc, which performs the MFCC processing.
5.3
Vector Quantization
The result of the last section is that we transform speech signals into vectors in an
acoustic space. In this section, we will apply the VQ-based pattern recognition technique
to build speaker reference models from those vectors in the training phase and then can
identify any sequences of acoustic vectors uttered by unknown speakers.
Question 7: To inspect the acoustic space (MFCC vectors) we can pick any two
dimensions (say the 5th and the 6th) and plot the data points in a 2D plane. Use acoustic
vectors of two different speakers and plot data points in two different colors. Do the data
regions from the two speakers overlap each other? Are they in clusters?
Now write a Matlab function, vqlbg that trains a VQ codebook using the LGB
algorithm described before. Use the supplied utility function disteu to compute the
pairwise Euclidean distances between the codewords and training vectors in the iterative
process.
Question 8:Plot the resulting VQ codewords after function vqlbg using the same
two dimensions over the plot of the previous question. Compare the result with Figure 5.
13
5.4
Simulation and Evaluation
Now is the final part! Use the two supplied programs: train and test (which
require two functions mfcc and vqlbg that you just complete) to simulate the training
and testing procedure in speaker recognition system, respectively.
Question 9: What is recognition rate our system can perform? Compare this with the
human performance. For the cases that the system makes errors, re-listen to the speech
files and try to come up with some explanations.
Question 10: You can also test the system with your own speech files. Use the
Window’s program Sound Recorder to record more voices from yourself and your
friends. Each new speaker needs to provide one speech file for training and one for
testing. Can the system recognize your voice? Enjoy!
14
‫یک سیستم خودکار شناسایی گوینده‬
‫‪1‬کلیات‬
‫شناسایی بلندگو‪ ،‬فرایند خودکار شناسایی بلندگو )گوینده( بر پایه‬
‫اطالعات شخصی در میان امواج صوتی است‪ .‬این تکنیک امکان کنترل هویت و‬
‫دسترسی افراد با استفاده از صدا و ارائه خدماتی مانند شمارهگیری‬
‫صوتی‪ ،‬بانکداری تلفنی‪ ،‬خرید تلفنی‪ ،‬خدمات پایگاه داده‪ ،‬خدمات‬
‫اطالعاتی‪ ،‬ایمیل صوتی‪،‬کنترل امنیتی برای مناطق اطالعات محرمانه و‬
‫دسترسی از راه دور به کامپیوتر را فراهم میکند‪.‬‬
‫این سند ساخت نمونه ساده را توضیح میدهد‪ .‬سیستم شناسایی گوینده‪،‬‬
‫پتانسیل استفاده در بسیاری از نرم افزارهای امنیتی را داراست‪ .‬برای‬
‫مثال‪ ،‬کاربران مجبور هستند برای ورود به درهای آزمایشگاهی پین‬
‫)شماره شناسایی شخصی( را بیان کنند‪ ،‬یا کاربران باید برای شناسایی‬
‫هویتشان شماره کارت شناسایی خود را پشت تلفن بگویند‪ .‬با بررسی‬
‫ویژگیهای صدای سخن گفتن ورودی با استفاده از سیستم شناسایی گوینده‬
‫شبیه چیزی که ما تعریف خواهیم نمود‪ ،‬این سیستم قادر به اضافه کردن‬
‫یک الیه امنیت بیشتر است‪.‬‬
‫‪2‬اصول تشخیص گوینده‬
‫شناساگر گوینده میتواند به دو بخش شناسایی و تایید طبقهبندی شود‪.‬‬
‫شناسایی گوینده فرایند تشخیص گوینده ثبت شده از روی سخن گفتن است‪.‬‬
‫تایید گوینده‪ ،‬از سوی دیگر‪ ،‬فرایند تایید یا عدم تایید صحت هویت یک‬
‫گوینده است‪ .‬شکل ‪ 1‬ساختار ساده سیستم شناسایی و تایید گوینده را‬
‫نشان میدهد‪ .‬سیستم مورد نظر به عنوان سیستم شناساگر گوینده مستقل از‬
‫متن طبقهبندی شده است‪ ،‬به عبارتی کار آن شناسایی فرد صرف نظر از آن‬
‫کهچه میگوید است‪.‬‬
‫در باالترین سطح‪ ،‬همه سیستمهای شناسایی گوینده شامل دو ماژول اصلی‬
‫هستند‪ :‬استخراج ویژگی و تطبیق ویژگی‪ .‬استخراج ویژگی فرایند بیرون‬
‫کشیدن مقدار کمی از دادههای سیگنال صوتی است که میتواند برای‬
‫نمایاندن هر گوینده استفاده شود‪ .‬تطبیق ویژگی شامل روش واقعی برای‬
‫شناسایی گوینده ناشناس با مقایسه ویژگیهای استخراج شده از صدای‬
‫ورودی وی با آنهایی که شناخته شده هستند‪ .‬در بخش بعد به شرح هر‬
‫ماژول میپردازیم‪. (a) Speaker identification (b) Speaker verification‬‬
‫شکل ‪ :1‬ساختار اساسی سیستم شناسایی گوینده‬
‫همه سیستمهای شناسایی گوینده باید در دو فاز اصلی خدمت کنند‪ .‬فاز‬
‫اول ثبت نام یا آموزش‪ ،‬و فاز دوم عملکرد یا تست است‪ .‬در فاز آموزش‪،‬‬
‫هر گوینده ثبت شده باید نمونهای از سخن گفتنشان را ارائه دهند تا‬
‫سیستم بتواند مدلی برای آن گوینده بسازد‪ .‬در مورد سیستم تطبیق‬
‫گوینده‪ ،‬بعالوه‪ ،‬یک آستانه زبان خاص نیز از نمونههای آموزشی تخمین‬
‫زده میشود‪ .‬در فاز تست‪ ،‬سخن ورودی با مدلهای ذخیره شده برای ارجاع‬
‫مقایسه شده و برای تایید تصمیم گرفته میشود‪.‬‬
‫شناسایی گوینده کار دشواری است‪ .‬سیستم شناسایی گوینده خودکار بر‬
‫اساس این فرض که سخن یک شخص ویژگیهای منحصر به فرد وی را داراست کار‬
‫میکند‪ .‬به هر حال این کار با تنوع باالی سیگنالهای گفتار ورودی به‬
‫‪15‬‬
‫چالش کشیده شده است‪ .‬منبع اصلی تنوع گویندگان هستند‪ .‬سیگنالهای سخن‬
‫در مراحل آموزش و تست میتواند تفاوت عمدهای داشته باشد‪ ،‬به دالیل‬
‫زیادی مانند تغییر صدا با زمان‪ ،‬بیماری )سرماخوردگی گوینده(‪ ،‬تن‬
‫صدای گفتار و مانند آن‪ .‬همچنین عوامل دیگری وجود دارد‪ ،‬فراتر از‬
‫تنوع گوینده‪ ،‬که در حال حاضر یک چالش برای تکنولوژی شناسایی گوینده‬
‫محسوب میشوند‪ .‬مثالهای این چالشها نویز و سروصدا و ضبط در محیط است‬
‫)به عنوان مثال استفاده از بلندگوهای گوشیهای متفاوت‪(.‬‬
‫‪3‬استخراج ویژگی گفتار‬
‫مقدمه‬
‫هدف از این ماژول برای تبدیل شکل موج گفتار‪ ،‬استفاده از ابزارهای‬
‫پردازش سیگنال دیجیتال (‪ )DSP‬برای تجزیه و تحلیل مجموعهای از ویژگیها‬
‫)با نرخ اطالعات پایین( است‪.‬سیگنال گفتار یک سیگنال وابسته به زمان‬
‫کند )شبه ثابت نامیده میشود( است‪ .‬یک مثال از سیگنال گفتار در‬
‫شکل ‪ 2‬نشان داده شده است‪ .‬زمانیکه بیش از یک دوره کوتاه زمانی کافی‬
‫)بین ‪ 5‬تا ‪ 111‬میلی ثانیه( را مورد بررسی قرار دهیم‪ ،‬ویژگیهای آن‬
‫ً ثابت هستند‪ .‬به هر حال‪ ،‬در طول دوره زمانی بلند )حدود ‪1/5‬‬
‫نسبتا‬
‫ثانیه یا بیشتر( ویژگیهای سیگنال برای بازتاب متفاوت در صحبت کردن‬
‫تغییر میکند‪ .‬بنابراین‪ ،‬آنالیز طیف زمان کوتاه معمولترین راه برای‬
‫مشخص کردن سیگنال گفتار است‪.‬‬
‫طیف گستردهای از احتماالت برای تشخیص سیگنال گفتار گوینده وجود دارد‪،‬‬
‫از جمله کدینگ پیشبینی خطی(‪ ، )LPC‬ضرایب ‪ Cepstrum Frequency-Mel‬و غیره ‪.‬‬
‫‪ ،MFCC‬شاید بهترین وشناخته شدهترین باشد و در این مقاله به شرح آن‬
‫خواهیم پرداخت‪.‬‬
‫‪MFCC‬ها بر پایه تنوع پهنای باند با فرکانس شناخته شده بحرانی گوش‬
‫انسان هستند‪ .‬فیلترهای خطی در فرکانسهای پایین و لگاریتمی در‬
‫فرکانسهای باال استفاده شده تا هم آوایی های مهم ویژگیهای گفتار را‬
‫دریافت کنند‪ .‬مقیاس فرکانس ‪ mel‬فاصله فرکانس خطی کمتر از ‪ 1111‬هرتز و‬
‫فاصله لگاریتمی بیشتر از ‪ 1111‬هرتز یان شده است‪ .‬این فرایند محاسبه‬
‫‪MFCC‬ها با جزئیات بیشتر در آینده توضیح داده خواهد شد‪.‬‬
‫پردازنده ضرایب ‪Cepstrum Frequency-Mel‬‬
‫یک بلوک دیاگرام از ساختار یک پردازنده ‪ MFCC‬در شکل ‪ 3‬داده شده است‪.‬‬
‫گفتار ورودی معموالً بانرخ نمونه برداری باالتر از ‪ 11111‬هرتز ضبط‬
‫میشود‪ .‬این فرکانس نمونه برداری برای به حداقل رساندن اثرات‬
‫‪aliasing‬در تبدیل آنالوگ به دیجیتال انتخاب شده است‪ .‬این سیگنالهای‬
‫نمونه میتوانند از هر فرکانسی تا ‪5‬کیلوهرتز ‪ ،‬که بیشترین انرژی صدا‬
‫که توسط انسان ساخته میشودگرفته شوند‪ .‬همانطور که قبال توضیح داده‬
‫شد‪ ،‬هدف اصلی پردازندههای ‪ MFCC‬تقلید رفتار گوش انسان است‪ .‬بعالوه‪،‬‬
‫به جای شکل موجهای گفتار خود‪MFCC ،‬ها حساسیت کمتری به تغییرات از‬
‫خود نشان دادهاند‪.Figure 3. Block diagram of the MFCC processor‬‬
‫مسدود کردن پنجره‬
‫در این مرحله سیگنال پیوسته گفتار به ‪ N‬پبجره نمونه برداری میشود‪،‬‬
‫پنجرههای مجاور یکدیگر با (‪ M ) > M N‬جدا میشوند‪ .‬پنجره اول شامل ‪N‬‬
‫‪16‬‬
‫نمونه اول است‪ .‬پنجره دوم ‪ M‬نمونه پس از پنجره اول شروع میشوند‪ ،‬و‬
‫همپوشانی نمونههای ‪ M-N‬و مانند آن اتفاق میافتد‪ .‬این فرایند تا زمانی‬
‫که همه سخن برای یک پنجره یا بیشتر‬
‫محسوب شود ادامه مییابد‪ .‬مقادیر معمول برای ‪ N‬و‪256 = N ) ، M‬که معادل ‪31‬‬
‫میلی ثانیه پنجره و تسهیل سریع مبنا فوریه است( و ‪= M.100‬‬
‫پنجره پنجره کردن‬
‫مرحله بعد پردازش هر پنجره برای به حداقل رساندن ناپیوستگی سیگنال‬
‫در آغاز و پایان هر پنجره است ‪.‬‬
‫مفهوم در اینجا به حداقل رساندن اعوجاج طیفی با استفاده از پنجره‬
‫برای صفر کاهش دادن سیگنال در آغاز و پایان هر پنجره است‪ .‬اگر پنجره‬
‫را تعریف کنیم‪ ،‬که در آن ‪ N‬تعداد نمونهها در هر پنجره باشد‪ ،‬در این‬
‫حالت نتیجه پنجره کردن سیگنال عبارت خواهد بود از‪:‬معموالً پنجره همینگ‬
‫استفاده میشود که به شکل زیر است‪:‬‬
‫تبدیل فوریه سریع‬
‫مرحله بعد پردازش تبدیل فوریه سریع‪ ،‬که تبدیل هر پنجره از ‪ N‬نمونه از‬
‫حوزه زمان به حوزه فرکانس است ‪. FFT‬یک الگوریتم سریع برای اجرای تبدیل‬
‫فوریه گسسته(‪ ، )DFT‬که در مجموعهای از ‪ N‬نمونه }‪{xn‬تعریف میشود است‪ ،‬به‬
‫شرح زیر‪:‬‬
‫به طور کلی ‪Xk‬ها اعداد مختلط هستند و ما تنها مقدار مطلق آنها را‬
‫در نظر میگیریم )مقدار فرکانس(‪ .‬در نتیجه دنباله }‪{Xk‬به شرح زیر‬
‫تفسیر میشود‪ :‬فرکانسهای مثبت مربوط به مقادیر در حالی که فرکانسهای‬
‫منفی مربوط به مقادیر هستند‪ .‬در اینجا‪Fs ،‬نشاندهنده فرکانس نمونه‬
‫برداری است‪.‬نتیجه پس از این مرحله اغلب به عنوان طیف یا مرتبه نگار‬
‫خواهد بود‪.‬‬
‫بسته بندی ‪frequency-Mel‬‬
‫همانطور که در باال اشاره شد‪ ،‬مطالعات روانی نشان داده است که درک‬
‫بشر از محتویات فرکانس صداها برای سیگنالهای گفتار از یک مقیاس خطی‬
‫پیروی نمیکند‪ .‬بنابراین برای هر تن با فرکانس واقعی که در واحد‬
‫هرتز اندازهگیری میشود‪ ،‬یک ‪ .‬مقیاس ‪frequency-mel‬یک فاصله فرکانسی خطی‬
‫کمتر از ‪ 1111‬هرتز و یک فاصله لگاریتمی باالی ‪ 1111‬هرتز است‪.‬‬
‫یک دیدگاه برای شبیه سازی طیف ذهنی استفاده از یک بانک فیلتر است‪،‬‬
‫که در مقیاس یکنواخت باشد )مانند شکل ‪ .(4‬این بانک فیلتر دارای پاسخ‬
‫فرکانسی مثلثی میانگذر‪ ،‬و فاصله آن مانند پهنای باند با یک فاصله مل‬
‫فرکانسی ثابت نعیین میشود‪ .‬تعداد ضرایب طیف مل‪ ،K ،‬به طور معمول ‪21‬‬
‫انتخاب میشود‪ .‬توجه داشته باشید این بانک فیلتر در دامنه فرکانس‬
‫اعمال میشود‪ ،‬بنابراین همانطور که در شکل ‪ 4‬مشاهده میشود به سادگی‬
‫میتوان پنجرههای مثلثی شکل را به طیف اعمال کرد‪.‬‬
‫‪Figure 4. An example of mel-spaced filterbank‬‬
‫یک راه مفید فکر کردن در مورد بانک بسته بندی مل‪ ،‬مشاهده هر فیلتر‬
‫به عنوان یک بن هیستوگرام )که در آن پایهها همپوشانی دارند( در‬
‫دامنه فرکانس است‪.‬‬
‫سپستروم‬
‫‪17‬‬
‫در گام آخر‪ ،‬ما به تبدیل طیف لگاریتمی مل به زمان اقدام میکنیم‪.‬‬
‫نتیجه ضرایب ‪Frequency-MelCepstrum‬گفته میشود ‪ )MFCC(.‬معرفی ‪cepstral‬از طیف‬
‫گفتار یک معرفی خوب از خواص طیفی محلی سیگنال برای تجزیه و تحلیل‬
‫پنجره فراهم میکند‪ .‬از آنجا که ضرایب طیفی مل )و به همین ترتیب‬
‫لگاریتم آن (اعداد حقیقی هستند‪ ،‬ما میتوانیم آنها را با استفاده از‬
‫تبدیل کسینوسی گسسته (‪ )DCT‬به حوزه زمان منتقل کنیم‪ .‬بنابراین اگر ما‬
‫ضرایب طیف قدرت مل را معنی کنیم که در نتیجه آخرین مرحله است‬
‫میتوانیم ‪ MFCC‬ها را محاسبه کنیم‪.‬توجه داشته باشید که ما اولین جز را‬
‫مستثنی میکنیم‪ ،‬از ‪ DCT‬تا آن را مقدار متوسط سیگنال ورودی معرفی کنیم‬
‫که حامل اطالعات کمی از گفتار گوینده است‪.‬‬
‫خالصه‬
‫با استفاده از فرایندی که در باال توضیح داده شد‪ ،‬برای هر پنجره‬
‫گفتار حدود ‪ 31‬میلی ثانیه با همپوشانی یک مجموعه از ضرایب ‪Cepstrum‬‬
‫‪Frequency-Mel‬محاسبه میشود‪ .‬این نتیجه تبدیل کسینوس لگاریتم طیف توان‬
‫در زمان کوتاه در مقیاس ‪frequency-mel‬است‪ .‬این مجموعه از ضرایب یک بردار‬
‫صوتی گفته میشود‪ .‬بنابراین هر سخن ورودی به یک دنباله از بردارهای‬
‫صوتی تبدیل میشود‪ .‬در بخش بعد خواهیم دید که چگونه میتوان‬
‫بردار صوتی را برای نشان دادن و شناسایی ویژگی صدای گوینده مورد‬
‫استفاده قرار داد‪.‬‬
‫‪4‬تطبیق ویژگی‬
‫مقدمه‬
‫مسئله شناسایی گوینده متعلق به یک موضوع بسیار گستردهتر در علم و‬
‫مهندسی به نام شناسایی الگو است ‪.‬‬
‫هدف از شناسایی الگو طبقه بندی موارد مورد عالقه به یکی از کالسها یا‬
‫مجموعهها است‪ .‬موارد مورد عالقه به صورت کلی الگو نامیده میشوند و در‬
‫مورد ما دنبالههایی هستند که از بردارهای صوتی که از گفتار ورودی با‬
‫استفاده از تکنیکهای شرح داده شده در بخش قبل استخراج شده است‪ .‬کالس‬
‫در اینجا اشخاص گوینده هستند‪ .‬از آنجا که فرایند طبقه بندی در مورد‬
‫ما بر ویژگیهای استخراج شده اعمال میشود‪ ،‬میتوان آن را نیز به تطبیق‬
‫ویژگی مربوط دانست‪.‬عالوه بر این‪ ،‬اگر برخی از مجموعه الگوها که کالسهای‬
‫فردی در حال حاضر شناخته شده وجود دارد و سپس یک مسئله نظارت تشخیص‬
‫الگو‪ .‬این الگوها شامل مجموعه آموزشی و مورد استفاده برای استخراج‬
‫الگوریتم طبقه بندی است‪ .‬الگوهای باقیمانده برای تست الگوریتم طبقه‬
‫بندی استفاده میشود‪ .‬این الگوها در مجموع به عنوان مجموعه تست ارجاع‬
‫میشود‪ .‬اگر کالسهای مشخص از الگوهای منحصر به فرد در این مجموعه تست‬
‫شناخته شده باشند پس از آن میتوان عملکرد الگوریتم را ارزیابی کرد‪.‬‬
‫تکنیکهای تطبیق ویژگیها در تشخیص هویت گوینده شامل پیچیدن زمان پویا‬
‫(‪ ،)DTW‬مدل مارکوف مخفی (‪ )HMM‬و بردار تعیین میزان (‪ )VQ‬استفاده‬
‫میشود‪ .‬در این پروژه‪ ،‬به علت سهولت اجرا و دقت باال ‪VQ‬استفاده‬
‫میشود ‪. VQ‬یک فرایند بردارهای نقشه برداری از یک فضای برداری بزرگ‬
‫برای یک تعداد محدود از نقاط در آن فضا است‪ .‬هر منطقه یک خوشه‬
‫نامیده میشود و میتواند توسط هسته آن با یک کد نشان نامیده شود‪.‬‬
‫‪18‬‬
‫مجموعه همه کد نشانها کتاب کد نامیده میشود‪.‬شکل ‪ 5‬یک نمودار مفهومی‬
‫برای نمایش این فرایند تشخیص را نشان میدهد‪ .‬در این شکل‪ ،‬تنها دو‬
‫گوینده و دو بعد از فضای آکوستیک نمایش داده شده است‪ .‬دایره به‬
‫بردارهای آکوستیک از گوینده شماره ‪ 1‬و مثلث به گوینده شماره ‪ 2‬اشاره‬
‫دارد‪ .‬در مرحله آموزش‪ ،‬با استفاده از الگوریتمهای خوشه بندی در بخش‬
‫قبل‪ ،‬کتاب کد ‪VQ‬یک گوینده خاص برای هر گوینده شناخته شده توسط خوشه‬
‫بندی بردارهای آموزش آکوستیک وی ساخته میشود‪ .‬کلمههای کد نتیجه‬
‫(‪)centroids‬در شکل ‪ 5‬با دایرههای سیاه و مثلثهای سیاه برای گوینده شماره ‪1‬‬
‫و سفید برای گوینده شماره ‪ 2‬نشان داده شده است‪ .‬فاصله از یک بردار‬
‫به نزدیکترین خوشه کلمه کد از یک کتاب کد اعوجاج ‪ VQ‬نامیده میشود‪.‬‬
‫در مرحله شناسایی‪ ،‬یک سخن ورودی از یک صدای ناشناس یک بردار‬
‫کوانتیزه است که با استفاده از هر کتاب کد آموزشی و اعوجاج ‪ VQ‬کل‬
‫محاسبه میشود‪ .‬گوینده مربوط به کتاب کد ‪ VQ‬با کوچکترین انحراف کل به‬
‫عنوان گوینده ورودی شناخته میشود ‪.Figure 5. Conceptual diagram illustrating vector quantization‬‬
‫‪codebook formation.One speaker can be discriminated from another based of the location of centroids.(Adapted from Song‬‬
‫)‪et al., 1987‬‬
‫خوشه بندی بردارهای آموزشی‬
‫پس از جلسه ثبت افراد‪ ،‬بردارهای آکوستیک استخراج شده از گفتار ورودی‬
‫هر گوینده برای یک مجموعه بردارهای آموزشی برای آن گوینده فراهم‬
‫میشود‪ .‬همانطور که در باال توضیح داده شد‪ ،‬گام مهم بعدی ساخت‬
‫یک کتاب کد ‪ VQ‬گوینده خاص برای هر گوینده با استفاده از بردارهای‬
‫آموزشی است‪ .‬یک الگوریتم شناخته شده به نام الگوریتم ‪ LBG‬برای خوشه‬
‫بندی یک مجموعه از ‪ L‬بردار آموزشی به مجموعهای از ‪ M‬بردارهای‬
‫کتاب کد وجود دارد‪ .‬الگوریتم به صورت رسمی با روش بازگشتی زیر اجرا‬
‫میشود ‪:1.‬طراحی یک بردار کتاب کد‪ :‬این مرکز ثقل کل مجموعهای از‬
‫بردارهای آموزشی است )از این رو‪ ،‬هیچگونه تکرار در اینجا مورد نیاز‬
‫نیست ‪(.2.‬دوبرابر کردن اندازه کتاب کد با تقسیم هر کتاب کد ‪yn‬فعلی با‬
‫توجه به قانون که در آن مقدار ‪ n‬از ‪ 1‬به اندازه فعلی کتاب کد بوده‪ ،‬و‬
‫یک پارامتر تقسیم است )ما ‪ 1011‬را انتخاب کردیم‪(.‬‬
‫‪3.‬جستجو نزدیکترین همسایگی‪ :‬برای هر بردار آموزشی‪ ،‬یافتن کد کلمه در‬
‫کتاب کد که نزدیکترین )از نظر فاکتورهای اندازهگیری شباهت( است‪ ،‬و‬
‫اختصاص دادن آن بردار به سلول مربوطه )مربوط به نزدیکترین کلمه کد(‬
‫‪4.‬به روز رسانی مرکز ثقل‪ :‬به روز رسانی کلمه کد در هر سلول با‬
‫استفاده از مرکز ثقل بردارهای آموزشی اختصاص داده شده به سلول‪.‬‬
‫‪5.‬ایتریشن ‪ :1‬تکرار مراحل ‪ 3‬و ‪ 4‬تا زمانی که متوسط فاصله کمتر از یک‬
‫آستانه از پیش تعیین شده شود‪.‬‬
‫‪6.‬ایتریشن ‪ :2‬تکرار مراحل ‪ 3،2‬و ‪ 4‬تا زمانی که به اندازه یک کتاب کد‬
‫از ‪ M‬طراحی شود‪.‬‬
‫به طور مستقیم‪ ،‬الگوریتم ‪ LBG‬یک بردار ‪ M‬کتاب کد را طی مراحلی طراحی‬
‫میکند‪ .‬در ابتدا با طراحی یک ‪1‬بردار کدبوک آغاز میشود‪ ،‬سپس با‬
‫استفاده از تکنیک تقسیم در کلمه کدها برای جستجو مقدار اولیه به ‪2‬‬
‫‪19‬‬
‫بردار کدبوک بهره گرفته‪ ،‬و در ادامه فرایند تقسیم تا زمانی که کدبوک‬
‫بردار ‪ M‬مورد نظر بدست آید‪.‬‬
‫شکل ‪ ،6‬در یک نمودار دنباله دار‪ ،‬جزئیات گامهای الگوریتم ‪ LBG‬را نشان‬
‫میدهد‪ .‬بردارهای خوشهای فرایند جستجو نزدیکترین همسایه که هر بردار‬
‫آموزشی را به خوشهای مرتبط با نزدیکترین کلمه کد اختصاص می‪-‬‬
‫دهد‪ .‬یافتن مرکز ثقل روش به روز رسانی شده مرکز ثقل است‪ .‬محاسبه‬
‫اعوجاج مجموع فواصل همه بردارهای آموزش در جستجو نزدیکترین همسایگی‬
‫است‪ ،‬بنابراین به عنوان تست همگرایی تعیین میشود‪.‬‬
‫)‪Figure 6. Flow diagram of the LBG algorithm (Adapted from Rabiner and Juang, 1993‬‬
‫‪5‬پروژه‬
‫همانطور که گفته شد‪ ،‬در این پروژه ما ساخت و آزمایش یک سیستم تشخیص‬
‫خودکار گوینده را تجربه خواهیم کرد‪ .‬به منظور ساخت چنین سیستمی‪،‬‬
‫باید مراحلی را که در بخشهای قبل توضیح داده شد طی شود ‪.‬‬
‫راحتترین فرم برای این محیط نرم افزار متلب است که بسیاری از کارهای‬
‫فوق در نرمافزار متلب به اجرا درآمده است‪ .‬صفحه پروژه وب داده شده‬
‫در ابتدا یک آزمایش پایگاه داده و چندین تابع کمکی برای ساده‬
‫کردن فرایند توسعه فراهم میکند‪ .‬ما دو تابع کاربردی را به شما عرضه‬
‫میکنیم ‪: melfb‬و ‪ disteu .‬و تابع اصلی ‪: train‬و ‪ test.‬همه این فایلها را از وب‬
‫سایت پروژه بر روی کامپیوتر خود دانلود کنید‪ .‬دو فایل اول می‪-‬‬
‫توانند به عنوان جعبه سیاه در نظر گرفته شوند‪ ،‬اما دو فایل بعدی‬
‫باید به طور کامل درک شوند‪ .‬در حقیقت‪ ،‬وظایف شما نوشتن دو تابع از‬
‫دست رفته است ‪: MFCC‬و‪ ، vqlbg‬که از توابع اصلی داده شده فراخوانی‬
‫خواهند شد‪ .‬به منظور اجرای آن‪ ،‬هر مرحله در این بخش را با دقت دنبال‬
‫و درک خود را با پاسخ دادن به سواالت بررسی کنید‪.‬‬
‫گفتار داده‬
‫از پایگاه داده گفتار روی صفحه وب پروژه فایل ‪ ZIP‬را دانلود کنید‪ .‬بعد‬
‫خارج کردن آن از حالت زیپ‪ ،‬شما باید دو پوشه پیدا کنید‪TRAIN ،‬و ‪TEST‬‬
‫که هرکدام شامل ‪ 8‬فایل هستند با نامهای ‪ ،: ,WAV.S1 WAV.S8 ,... ,WAV.S2‬هر‬
‫کدام بعد از مشخصات گوینده برچسب خوردهاند‪ .‬این فایلها با فرمت‬
‫مایکرسافت ویو ضبط شده است‪ .‬در سیستم ویندوز‪ ،‬شما میتوانید با دوبار‬
‫کلیک روی آنها صداهای ضبط شده را گوش دهید‪.‬‬
‫هدف ما تمرین یک مدل صدا )و یا مشخصتر‪ ،‬یک کدبوک ‪ VQ‬در بردار ‪MFCC‬‬
‫است( برای هر گوینده ‪ S1‬تا ‪ S2‬با استفاده از فایل صوتی مربوطه در پوشه‬
‫‪TRAIN‬است‪ .‬پس از این مرحله تمرین‪ ،‬سیستم باید از ویژگیهای صدای هر‬
‫گوینده شناخته شده آگاهی داشته باشد‪ .‬سپس‪ ،‬در مرحله آزمایش‪ ،‬سیستم‬
‫باید قادر به شناسایی گوینده هر یک از فایلهای موجود در پوشه ‪TEST‬‬
‫باشد‪.‬‬
‫سوال ‪ .1‬هر یک از صداهای پوشه ‪ TRAIN‬را اجرا کنید‪ .‬آیا میتوانید صدای‬
‫هشت گوینده را در پایگاه داده تشخیص دهید؟ اکنون هر یک از صداهای‬
‫پوشه ‪ TEST‬را به صورت تصادفی و بدون نگاه کردن به نام آنها‬
‫)به گونه ای که گوینده برای شما ناشناس بماند( اجرا و سعی کنید‬
‫گوینده را با استفاده دانش خود نسبت به صدای آنها که فقط از پوشه‬
‫ً همان چیزی است که کامپیوتر‬
‫‪TRAIN‬آموختهاید تشخیص دهید‪ .‬این دقیقا‬
‫‪20‬‬
‫ نرخ تشخیص )عملکرد انسان( چقدر است؟‬.‫در سیستم ما انجام خواهد داد‬
‫ثبت این نتیجه میتواند در آینده برای مقایسه درمقابل عملکردکامپیوتر‬
.‫در سیستم ما قرار گیرد‬
‫پردازش گفتار‬
‫در این مرحله شما نیاز به نوشتن یک تابع متلب که یک فایل صوتی را‬
‫خوانده و با استفاده از مراحل پردازش گفتار که قبالً مطرح شد آن را به‬
‫ بسیاری از‬.‫ بردارهای آکوستیک( برگرداند دارید‬MFCC )‫یک دنباله‬
‫این وظایف در حال حاضر به صورت استاندارد یا با توابع متلب ما ارائه‬
: dct ,fft ‫ توابعی که شما در متلب به آنها نیاز دارید‬.‫شده است‬
‫ برای اطالعات بیشتر در‬.(‫تابع ارائه شده‬melfb ) ‫و‬,hamming ,wavread
.‫مورد این سه تابع نام تابع را در هلپ متلب بنویسید‬
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s1.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s2.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s3.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s4.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s5.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s6.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s7.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s4.wav');
m = 100;
n = 256;
l = length(y);
framebiocking = floor((l - n) / m) + 1;
for i = 1:n
for j = 1:framebiocking
M(i, j) = y(((j - 1) * m) + i);
end
end
plot(M)
imagesc(M)
21
‫سوال ‪ :2‬یک فایل صوتی را در متلب بخوانید‪ .‬برای تست‪ ،‬فایل صوتی را‬
‫در متلب با استفاده از تابع ‪sound‬اجرا کنید‪ .‬نرخ نمونه برداری چیست؟‬
‫باالترین فرکانس که صدای ضبط شده میتواند با دقت بگیرد چیست؟ با‬
‫این نرخ نمونه برداری‪ ،‬یک بلوک نمونه ‪ 256‬شامل چند میلی ثانیه از‬
‫گفتارهای واقعی است؟‬
‫برای دیدن سیگنال آن را در حوزه زمان رسم کنید‪ .‬باید واضح باشد که‬
‫در حوزه زمان دادههای خام دارای مقدار داده بسیار باالیی هستند و این‬
‫برای تجزیه و تحلیل ویژگیهای صدا دشوار است‪ .‬بنابراین هدف از‬
‫این مرحله )استخراج ویژگی گفتار( باید روشن باشد!اکنون سیگنال گفتار‬
‫را )یک بردار( به پنجرههای دارای همپوشانی برش میدهیم‪ .‬نتیجه یک‬
‫‪22‬‬
‫ نمونه برای سیگنال اصلی‬N ‫ماتریس است که هر ستون آن یک پنجره از‬
‫ را برای انتقال سیگنال به حوزه‬FFT ‫ مراحل پنجره کردن و‬.‫گفتار است‬
‫ این فرایند در بسیاری از برنامهها استفاده‬.‫فرکانس اعمال مینماییم‬
‫) یا تبدیل فوریه کوتاه‬WFT( ‫میشود و در اصطالح تبدیل فوریه پنجره شده‬
‫ در نتیجه اغلب به عنوان طیف یا پریودوگرام‬.‫) گفته میشود‬STFT( ‫مدت‬
.‫نامیده میشود‬
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s1.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s2.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s3.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s4.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s5.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s6.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s7.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s4.wav');
m = 100;
n = 256;
l = length(y);
framebiocking = floor((l - n) / m) + 1;
for i = 1:n
for j = 1:framebiocking
M(i, j) = y(((j - 1) * m) + i);
end
h = hamming(n);
M2 = diag(h) * M;
end
plot(M2)
imagesc(M2)
23
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s1.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s2.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s3.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s4.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s5.wav');
24
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s6.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s7.wav');
[y, fs] = wavread('C:\Users\lenovo-\Desktop\DSP\data\train\s4.wav');
m = 100;
n = 256;
l = length(y);
framebiocking = floor((l - n) / m) + 1;
for i = 1:n
for j = 1:framebiocking
M(i, j) = y(((j - 1) * m) + i);
end
h = hamming(n);
M2 = diag(h) * M;
for i = 1:framebiocking
frame(:,i) = fft(M2(:, i));
end
end
plot(frame)
‫ تفسیر نتیجه حاصل چیست؟ طیف‬،‫ پس از اجرای موفق فرایند قبلی‬:3 ‫سوال‬
‫ توجه‬.‫کنید‬imagesc ‫توان را محاسبه و آن را با استفاده از دستور رسم‬
‫داشته باشید که برای بهتر دیدن طیف توان به مقیاس لگاریتمی وارد‬
‫ این نقطه را به‬.‫ نقطه که بیشترین انرژی را دارد مشخص کنید‬.‫میشویم‬
‫محدوده واقعی در زمان )میلی ثانیه (و در فرکانس )هرتز( سیگنال گفتار‬
.‫ورودی ترجمه کنید‬
25
‫;‪t = n / 2‬‬
‫;‪tmax = l / fs‬‬
‫;)‪m = melfb(20, n, fs‬‬
‫;)‪n2 = 1 + floor(n / 2‬‬
‫;‪out = m * abs(frame(1:n2, :)).^2‬‬
‫)‪plot(out‬‬
‫سوال ‪ :4‬طیف توان یک فایل گفتار را با استفاده از اندازه فریمهای‬
‫متفاوت محاسبه و رسم کنید‪ :‬برای مثال در‬
‫‪512 ,256 ,128 = N.‬در هر مورد‪ ،‬فریم را ‪ M‬را به اندازه حدود ‪/N 3‬‬
‫انتخاب کنید‪ .‬آیا شما میتوانید‬
‫تفاوتهای بین آن طیفها را توصیف و تشریح کنید؟‬
‫آخرین مرحله در پردازش گفتار تبدیل طیف توان به ضرایب ‪cepstrum‬‬
‫‪frequency-mel‬است‪ .‬تابع ‪melfb‬این وظیفه را تسهیل میکند‪.‬‬
‫)‪function m = melfb(p, n, fs‬‬
‫;‪f0 = 700 / fs‬‬
‫;)‪fn2 = floor(n/2‬‬
‫;)‪lr = log(1 + 0.5/f0) / (p+1‬‬
‫;))‪bl = n * (f0 * (exp([0 1 p p+1] * lr) - 1‬‬
‫;‪b1 = floor(bl(1)) + 1‬‬
‫;))‪b2 = ceil(bl(2‬‬
‫;))‪b3 = floor(bl(3‬‬
‫;‪b4 = min(fn2, ceil(bl(4))) - 1‬‬
‫;‪pf = log(1 + (b1:b4)/n/f0) / lr‬‬
‫;)‪fp = floor(pf‬‬
‫;‪pm = pf - fp‬‬
‫;])‪r = [fp(b2:b4) 1+fp(1:b3‬‬
‫;‪c = [b2:b4 1:b3] + 1‬‬
‫;])‪v = 2 * [1-pm(b2:b4) pm(1:b3‬‬
‫;)‪m = sparse(r, c, v, p, 1+fn2‬‬
‫‪26‬‬
‫سوال ‪ :5‬برای اطالعات بیشتر در مورد تابع ‪melfb help‬را در متلب تایپ‬
‫کنید‪ .‬برای رسم بانک فیلتر ‪spaced-mel‬دستورالعمل را دنبال کنید‪.‬‬
‫رفتار این بانک فیلتر چگونه است؟ آن را با بخش تئوری مقایسه کنید‪.‬‬
‫‪27‬‬
function M3 = blockFrames(s, fs, m, n)
l = length(s);
Frame = floor((l - n) / m) + 1;
for i = 1:n
for j = 1:Frame
M(i, j) = s(((j - 1) * m) + i);
end
end
h = hamming(n);
M2 = diag(h) * M;
28
‫‪for i = 1:Frame‬‬
‫;))‪M3(:, i) = fft(M2(:, i‬‬
‫‪end‬‬
‫سوال ‪ :6‬طیف فایل گفتار را قبل و بعد از مرحله ‪wrapping frequency-mel‬محاسبه و‬
‫رسم کنید‪ .‬تاثیر برنامه ‪melfb‬را توصیف و تشریح کنید‪.‬‬
‫در نهایت‪ ،‬مرحله ‪Cepstrum‬را کامل کرده و تمام قطعات را در یک تابع مستقل‬
‫متلب‪ ،mfcc ،‬که پردازش ‪MFCC‬را انجام میدهد کنار یکدیگر قرار دهید ‪.‬‬
‫‪29‬‬
‫)‪function r = mfcc(s, fs‬‬
‫;‪m = 100‬‬
‫;‪n = 256‬‬
‫;)‪l = length(s‬‬
‫;‪nbFrame = floor((l - n) / m) + 1‬‬
‫‪for i = 1:n‬‬
‫‪for j = 1:nbFrame‬‬
‫;)‪M(i, j) = s(((j - 1) * m) + i‬‬
‫‪end‬‬
‫‪end‬‬
‫;)‪h = hamming(n‬‬
‫;‪M2 = diag(h) * M‬‬
‫‪for i = 1:nbFrame‬‬
‫;))‪frame(:,i) = fft(M2(:, i‬‬
‫‪end‬‬
‫;‪t = n / 2‬‬
‫;‪tmax = l / fs‬‬
‫;)‪m = melfb(20, n, fs‬‬
‫;)‪n2 = 1 + floor(n / 2‬‬
‫;‪z = m * abs(frame(1:n2, :)).^2‬‬
‫;))‪r = dct(log(z‬‬
‫کوانتیزه کردن بردار‬
‫نتیجه آخرین مرحله این است که ما سیگنالهای گفتار را به بردارهایی‬
‫در فضای آکوستیک تبدیل میکنیم‪ .‬در این مرحله‪ ،‬ما تکنیک تشخیص الگوی‬
‫برپایه ‪ VQ‬را برای ساخت مدلهای مرجع گوینده از یردارهای آنها در‬
‫فاز آموزش اعمال خواهیم کرد و سپس میتوانیم هر دنباله از بردارهای‬
‫آکوستیکی ادا شده توسط گوینده ناشناس را شناسایی کنیم‪.‬‬
‫)‪function r = vqlbg(d,k‬‬
‫‪30‬‬
‫‪e‬‬
‫;‪= .01‬‬
‫‪r‬‬
‫;)‪= mean(d, 2‬‬
‫;‪dpr = 10000‬‬
‫)‪for i = 1:log2(k‬‬
‫;])‪r = [r*(1+e), r*(1-e‬‬
‫)‪while (1 == 1‬‬
‫;)‪z = disteu(d, r‬‬
‫;)‪[m,ind] = min(z, [], 2‬‬
‫;‪t = 0‬‬
‫‪for j = 1:2^i‬‬
‫;)‪r(:, j) = mean(d(:, find(ind == j)), 2‬‬
‫;))‪x = disteu(d(:, find(ind == j)), r(:, j‬‬
‫)‪for q = 1:length(x‬‬
‫;)‪t = t + x(q‬‬
‫‪end‬‬
‫‪end‬‬
‫)‪if (((dpr - t)/t) < e‬‬
‫;‪break‬‬
‫‪else‬‬
‫;‪dpr = t‬‬
‫‪end‬‬
‫‪end‬‬
‫‪end‬‬
‫سوال ‪ :7‬برای رسیدگی به فضای آکوستیک )بردارهای (‪MFCC‬میتوانیم هریک‬
‫از دو بعد )پنجمین و ششمین گفته میشوند( را انتخاب و نقاط داده در‬
‫یک طرح دوبعدی را رسم کنیم‪ .‬از بردارهای آکوستیک دو گوینده‬
‫متفاوت استفاده و نقاط داده را در دو رنگ مختلف رسم کنید‪ .‬آیا نقاط‬
‫داده دو گوینده با یکدیگر همپوشانی دارند؟ آیا در خوشه هستند؟‬
‫اکنون یک تابع متلب ‪vqlbg‬که یک کدبوک ‪ VQ‬را با استفاده از الگوریتم‬
‫‪LGB‬که قبال توضیح داده شد تمرین میکند بنویسید‪ .‬از تابع کاربردی‬
‫‪disteu‬برای محاسبه فواصل اقلیدسی بین کلمه کدها و بردارهای تمرینی‬
‫در فرایند تکرار شونده استفاده کنید‪.‬‬
‫سوال ‪ :8‬پس از تابع ‪vqlbg‬نتیجه کلمه کدهای ‪ VQ‬را با استفاده از دو‬
‫بعد رسم شده در سوال قبل رسم کنید‪ .‬نتیجه را با شکل ‪ 5‬مقایسه کنید‪.‬‬
‫)‪function d = disteu(x, y‬‬
‫;)‪[M, N] = size(x‬‬
‫;)‪[M2, P] = size(y‬‬
‫)‪if (M ~= M2‬‬
‫)'‪error('Matrix dimensions do not match.‬‬
‫‪31‬‬
‫‪end‬‬
‫;)‪d = zeros(N, P‬‬
‫)‪if (N < P‬‬
‫;)‪copies = zeros(1,P‬‬
‫‪for n = 1:N‬‬
‫;)‪d(n,:) = sum((x(:, n+copies) - y) .^2, 1‬‬
‫‪end‬‬
‫‪else‬‬
‫;)‪copies = zeros(1,N‬‬
‫‪for p = 1:P‬‬
‫;')‪d(:,p) = sum((x - y(:, p+copies)) .^2, 1‬‬
‫‪end‬‬
‫‪end‬‬
‫;‪d = d.^0.5‬‬
‫)‪function code = train(traindir, n‬‬
‫;‪k = 16‬‬
‫‪for i = 1:n‬‬
‫;)‪f = sprintf('%ss%d.wav', traindir, i‬‬
‫;)‪disp(f‬‬
‫‪[s, fs] = wavread('C:\Users\lenovo‬‬‫;)‪\Desktop\DSP\DSP_CLASS\test\',8‬‬
‫;)‪v = mfcc(s, fs‬‬
‫;)‪code{i} = vqlbg(v, k‬‬
‫‪end‬‬
‫شبیه سازی و ارزیابی‬
‫اکنون بخش نهایی! با استفاده از دو برنامه ارائه شده‪ :‬آموزش و آزمون‬
‫)که نیاز به دو تابع ‪mfcc‬و ‪vqlbg‬که کامل نمودید دارد( که برای شبیه‬
‫سازی فرایند آموزش و آزمون در سیستم تشخیص گوینده بود اقدام نمایید‪.‬‬
‫سوال ‪ :9‬نرخ تشخیص سیستم ما چقدر میتواند باشد؟ این را با عملکرد‬
‫انسان مقایسه کنید‪ .‬برای مواردی که سیستم که اشتباه میکند‪ ،‬دوباره‬
‫به فایلهای گفتار گوش داده و سعی کنید با برخی توضیحات توجیح کنید‪.‬‬
‫‪/‬سوال ‪ :10‬همچنین شما میتوانید سیستم را با گفتار خود تست کنید‪ .‬از‬
‫پنجرههای ضبط صدای برنامه برای ضبط صداهای بیشتر از خود و دوستانتان‬
‫استفاده کنید‪ .‬هر گوینده جدید نیاز به ارائه یک فایل گفتار برای‬
‫تمرین و یکی برای آزمون دارد‪ .‬سیستم میتواند صدای شما را تشخیص دهد؟‬
‫لذت ببرید‬
‫)‪function test(testdir, n, code‬‬
‫‪for k = 1:n‬‬
‫‪32‬‬
f = sprintf('%ss%d.wav', testdir, k);
[s, fs] = wavread('C:\Users\lenovo\Desktop\DSP\DSP_CLASS\test\',8,code);
v = mfcc(s, fs);
distmin = inf;
k1 = 0;
for l = 1:length(code)
d = disteu(v, code{l});
dist = sum(min(d,[],2)) / size(d,1);
if dist < distmin
distmin = dist;
k1 = l;
end
end
msg = sprintf('Speaker %d matches with speaker %d', k,
k1);
disp(msg);
end
33
34