|
Image Recognition
|
bet | 158/182 | Sana | 19.05.2024 | Hajmi | 5,69 Mb. | | #244351 |
Bog'liq Python sun\'iy intellekt texnologiyasi Dasrlik 2024Kutubxonani o‘rnatish:
Nutqni aniqlash kutubxonasini o‘rnating.
pip install SpeechRecognition
Audio fayldan nutqni taniydigan oddiy skript yarating.
import speech_recognition as sr
def recognize_speech(audio_path): # Ob’ektni ishga tushirish
Ma’lumotlarni qayta ishlash:
Libros kutubxonasi yordamida audio fayllarni qayta ishlash va xususiyatlarni chiqarish uchun skript yarating.
import librosa
import librosa.display
import numpy as np
import matplotlib.pyplot as plt # Audio fayldan xususiyatlarni chiqarish funktsiyasi
def extract_features(file_path):
audio_data, _ = librosa.load(file_path, duration=2.97)
mfccs = librosa.feature.mfcc(y=audio_data, sr=22050, n_mfcc=13)
return mfccs # Foydalanish misoli
file_path = "UrbanSound8K/audio/fold1/101415-3-0-2.wav"
features = extract_features(file_path) # Belgilarni vizualizatsiya qilish
plt.figure(figsize=(10, 4))
librosa.display.specshow(features, x_axis='time’)
plt.colorbar()
plt.title('MFCC')
plt.show()
Oldindan tayyorlangan modeldan foydalanish:
Ushbu tovush hodisalarini tasniflash uchun oddiy modelni yaratamiz va uni ma’lumotlar to‘plamining bir qismiga o‘rgatamiz.
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from tensorflow.keras import layers, models # Yorliqlar va ma’lumotlarni tayyorlash
labels = ["car_horn", "dog_bark", "siren", "street_music"]
X, y = [], []
for label in labels:
files = librosa.util.find_files(f"UrbanSound8K/audio/fold1/{label}/*.wav")
for file in files:
features = extract_features(file)
X.append(features)
y.append(label)
X = np.array(X)
y = np.array(y)# Yorliqlarni kodlash
label_encoder = LabelEncoder()
y_encoded = label_encoder.fit_transform(y)
X_train, X_test, y_train, y_test = train_test_split(X, y_encoded, test_size=0.2, random_state=42)# Tasniflash uchun oddiy neyron tarmoqni yaratish
model = models.Sequential([
layers.Flatten(input_shape=(X_train.shape[1], X_train.shape[2])),
layers.Dense(256, activation='relu'),
layers.Dropout(0.5),
layers.Dense(len(labels), activation='softmax')])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) # Modelni o‘qitish
model.fit(X_train, y_train, epochs=10, validation_data=(X_test, y_test))
Ovozli Hodisalarni Aniqlash:
Endi model o‘qitilgandan so‘ng, biz undan ovozli hodisalarni aniqlash uchun foydalanishimiz mumkin.
def predict_sound_event(model, file_path):
features = extract_features(file_path)
features = np.expand_dims(features, axis=0)
prediction = model.predict(features)
predicted_label = labels[np.argmax(prediction)]
return predicted_label # Foydalanish misoli
test_file_path = "UrbanSound8K/audio/fold1/101415-3-0-2.wav"
predicted_label = predict_sound_event(model, test_file_path)
print("Predicted Sound Event:", predicted_label)
Ushbu misol librosa kutubxonasi va TensorFlow yordamida tovush hodisalarini tasniflash uchun oddiy model yaratilishini ko‘rsatadi. Haqiqiy ilovalar o‘rganish uchun yanada murakkab modellar va keng ma’lumotlarni talab qilishi mumkin.
Xulosa
Ushbu tadqiqot davomida Python dasturlash tilida sun’iy intellekt yordamida audio ma’lumotlarni qayta ishlash sohasini o‘rganish bo‘yicha batafsil ishlar olib borildi. Ushbu sohaga kirish bizga akustik tahlil va sun’iy intellektni birlashtirgan zamonaviy texnologiyalar dunyosiga sho‘ng’ish uchun noyob imkoniyatni taqdim etdi.
Bizning tadqiqotlarimiz ovozni qayta ishlashga ixtisoslashgan kuchli Python kutubxonalaridan foydalangan holda audio analitik dasturlarni yaratishning amaliy jihatlariga qaratilgan. Ovozli ma’lumotlarni samarali tahlil qilish va qayta ishlash uchun librosa, PyDub va boshqalar kabi vositalardan foydalanish muhimligini ta’kidladik.
Loyiha davomida ovozni aniqlash va tahlil qilish sohasida sun’iy intellektni qo‘llash misollari ishlab chiqildi va muvaffaqiyatli amalga oshirildi. Bunga nutqni aniqlash, audio signallarni tasniflash va audio tahlilning boshqa jihatlari kabi vazifalar kiritilgan. Python platformasida dastur ma’lumotlarini amalga oshirish nafaqat uning ko‘p qirraliligini namoyish etadi, balki tadqiqot va muhandislik sohasida rivojlanish uchun keng istiqbollarni ham ochib beradi.
|
| |