اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release بدلاً من aosp-main لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توفّر ميزة "الاستجابة للصوت" للتطبيقات إمكانية الاستماع إلى
أحداث صوتية معيّنة، مثل الكلمات المفتاحية، بطريقة تستهلك طاقة منخفضة وتراعي الخصوصية.
تشمل أمثلة حالات استخدام "مشغِّل الصوت" "مساعد Google" و"المحتوى الذي يتم تشغيله حاليًا".
تقدّم هذه الصفحة نظرة عامة على بنية "مشغِّل الصوت" وواجهة HAL
(Hardware Abstraction Layer).
تسلسل بدء الصوت
تم إنشاء النظام الفرعي "مشغّل الصوت" في طبقات كما هو موضّح في الشكل 1:
الشكل 1: تسلسل عامل تشغيل الصوت
توضّح القائمة التالية كل طبقة معروضة في الشكل 1 بمزيد من التفصيل:
تحتوي طبقة HAL (باللون الأخضر) على الرمز البرمجي الخاص بالمورّد الذي
ينفّذ واجهة HAL لتشغيل الصوت (STHAL).
يظهر الرمز SoundTriggerMiddleware (باللون الأصفر) أعلى واجهة HAL. ويتواصل مع HAL وهو مسؤول عن وظائفه،
مثل مشاركة HAL بين العملاء المختلفين، والتسجيل، وفرض
الأذونات، ومعالجة التوافق مع الإصدارات القديمة من HAL.
يقع نظام SoundTriggerService (باللون الأزرق) فوق الوسيط.
ويسهّل هذا الدمج مع ميزات النظام الأخرى، مثل ميزات الهاتف ومقاييس
البطارية. ويحتفظ هذا النموذج أيضًا بقاعدة بيانات للنماذج الصوتية التي يتم فهرستها باستخدام معرّفات فريدة.
فوق طبقة SoundTriggerService، تعالج الحزمة (باللون البني) الميزات الخاصة بتطبيق "مساعد Google" والتطبيقات العامة بشكل منفصل.
وظيفة حزمة "مشغِّل الصوت" هي تقديم أحداث منفصلة تمثل أحداثًا صوتية مُشغِّلة. في معظم الحالات، لا تتعامل حزمة Sound Trigger
مع الصوت. عند تلقّي أحداث التفعيل، يمكن للتطبيقات الوصول إلى مجرى الصوت
الحقييقي المحيط بوقت الأحداث، وذلك من خلال فتح عنصر
AudioRecord عبر إطار عمل الصوت. توفّر واجهات برمجة التطبيقات HAL لميزة "التشغيل الصوتي"
اسمًا مع الحدث الذي تم تشغيله والذي يتم استخدامه مع "إطار عمل الصوت". وبالتالي،
بما أنّ Sound Trigger HAL وAudio HAL مرتبطان في الخلفية، فإنه
يتم عادةً مشاركة عملية بينهما.
واجهة Sound Trigger HAL
واجهة HAL الخاصة بميزة "الاستجابة للصوت" (STHAL) هي الجزء الخاص بالمورّد من حزمة "الاستجابة للصوت"، وهي تتعامل مع التعرّف على الكلمات المفتاحية والأصوات الأخرى من خلال الأجهزة.
توفّر STHAL محرّكًا واحدًا أو أكثر، ويعمل كل محرّك منها على تشغيل خوارزمية مختلفة
مصمّمة لرصد فئة معيّنة من الأصوات. عندما يرصد STHAL عامل تشغيل، فإنه
يرسل حدثًا إلى إطار العمل ثم يوقف عملية رصده.
يتم تحديد واجهة STHAL ضمن /hardware/interfaces/soundtrigger/.
تتيح واجهة ISoundTriggerHw إمكانية تنفيذ جلسة واحدة أو أكثر من جلسات الرصد في وقت معيّن والاستماع إلى الأحداث الصوتية.
تؤدي الدعوة إلى ISoundTriggerHw.getProperties() إلى عرض بنية Properties
تتضمّن وصف التنفيذ وإمكاناته.
في الشكل 2، يتم شرح الخطوات الأساسية لإعداد جلسة على النحو التالي:
الشكل 2: مخطّط الحالة STHAL
توضِّح الخطوات التالية كل حالة بمزيد من التفصيل:
يحمِّل برنامج HAL نموذجًا باستخدام loadSoundModel() أو
loadPhraseSoundModel(). يشير عنصر النموذج المقدَّم إلى
خوارزمية الكشف (المحرّك) الخاصة بالتنفيذ التي يجب استخدامها، بالإضافة إلى
المَعلمات السارية على هذه الخوارزمية. عند نجاح هذه الطرق، تُعرِض علامة ملف شخصي
تُستخدَم للإشارة إلى هذا النموذج في طلبات البيانات اللاحقة.
بعد تحميل النموذج بنجاح، يُجري برنامج HAL العميل مكالمة لبدء الكشف عن
startRecognition(). يستمر تشغيل ميزة التعرّف في
الخلفية إلى أن يحدث أحد الحدثَين التاليَين:
تمّ استدعاء stopRecognition() في هذا النموذج.
تم رصد محتوى.
يتم إيقاف عملية رصد المحتوى بسبب قيود الموارد، على سبيل المثال، عند بدء
حالة استخدام ذات أولوية أعلى.
في الحالتَين الأخيرتَين، يتم إرسال حدث التعرّف من خلال واجهة callback
التي يسجّلها عميل HAL عند التحميل. في جميع الحالات،
بعد وقوع أيّ من هذه الأحداث، يصبح نظام رصد الوجوه غير نشط ولا يُسمح بعد ذلك
بتلقّي طلبات إعادة الاتصال لميزة التعرّف على الوجوه.
يمكن بدء النموذج نفسه مرة أخرى في وقت لاحق، ويمكن تكرار هذه العملية
بقدر ما يلزم.
أخيرًا، يُزيل العميل HAL
النموذج غير النشط الذي لم يعُد مطلوبًا من خلال unloadModel().
التعامل مع أخطاء HAL
لضمان السلوك الموثوق والمُتسق بين عمليات تنفيذ برامج تشغيل الأجهزة، في الإصدار
Android 11، يتم التعامل مع أي رموز خطأ تشير إلى عدم النجاح يتم عرضها من
HAL على أنّها أخطاء برمجية، ويتطلّب استردادها
إعادة تشغيل عملية HAL. هذه هي استراتيجية الاسترداد كحل أخير، ومن المفترض أنّه لن تحدث مثل هذه الحالات في نظام يعمل بشكل صحيح.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Sound Trigger\n\nThe Sound Trigger feature provides apps with the ability to listen for certain\nacoustic events, like hotwords, in a low-power and privacy-sensitive manner.\nExample use cases of Sound Trigger are Assistant and Now Playing.\n\nThis page gives an overview of the Sound Trigger architecture and its HAL\n(Hardware Abstraction Layer) interface.\n\nSound Trigger stack\n-------------------\n\nThe Sound Trigger subsystem is built in layers as shown in Figure 1:\n\n**Figure 1:** Sound Trigger stack\n\nThe following list describes each layer shown in Figure 1 in more detail:\n\n- The **HAL layer** (in green) contains the vendor specific code which\n implements the [Sound Trigger HAL](#sthal-interface) (STHAL) interface.\n\n | **Note:** A direct implementation of the STHAL interface is recommended rather than as an adapter around an implementation of a legacy HAL.\n- The **`SoundTriggerMiddleware`** (in yellow) resides above the HAL\n interface. It communicates with the HAL and is responsible for functionalities\n such as sharing the HAL between different clients, logging, enforcing\n permissions and handling compatibility with older HAL versions.\n\n- The **`SoundTriggerService`** (in blue) system resides above the middleware.\n It facilitates integration with other system features, such as telephony and\n battery events. It also maintains a database of sound models, indexed by unique\n IDs.\n\n- Above the `SoundTriggerService` layer, the stack (in brown) handles features\n specific to Assistant and generic apps separately.\n\nThe function of the Sound Trigger stack is to deliver discrete events that\nrepresent acoustic, trigger events. In most cases, the Sound Trigger stack does\nnot deal with audio. Upon receipt of the trigger events, apps get access to the\nactual audio stream, surrounding the time of the events, by opening an\n`AudioRecord` object via the Audio framework. The Sound Trigger HAL APIs provide\na handle with the triggered event that is used with the Audio Framework. Hence,\nsince the Sound Trigger HAL and Audio HAL are connected under the hood, they\ntypically share a process.\n| **Note:** Since models and data types are opaque to the framework in the Sound Trigger subsystem, it is expected that apps and the HAL implementation maintain a \"hidden contract\", that is, the actual contents, format and semantics of those data types are agreed upon. Hence, apps using Sound Trigger are intended to be vendor provided rather than by independent developers.\n\nSound Trigger HAL interface\n---------------------------\n\nThe Sound Trigger HAL (STHAL) interface is the vendor specific part of the Sound\nTrigger stack and it handles hardware recognition of hotwords and other sounds.\nSTHAL provides one or more engines with each one running a different algorithm\ndesigned to detect a specific class of sounds. When STHAL detects a trigger, it\nsends an event to the framework and then stops the detection.\n\nThe STHAL interface is specified under `/hardware/interfaces/soundtrigger/`.\n\nThe `ISoundTriggerHw` interface supports the ability to have one or more\ndetection sessions running at a given time and to listen to acoustic events.\nA call to `ISoundTriggerHw.getProperties()` returns a `Properties` structure\ncontaining implementation description and capabilities.\n\nThe basic flow of setting up a session is explained as follows in Figure 2:\n\n**Figure 2:** STHAL state diagram\n\nThe following steps describe each state in more detail:\n\n1. The HAL client loads a model using `loadSoundModel()` or\n `loadPhraseSoundModel()`. The provided model object indicates which\n implementation-specific detection algorithm (engine) to use, as well as the\n parameters applicable for this algorithm. Upon success, these methods return a\n handle which is used to reference this model in subsequent calls.\n\n2. Once the model has been successfully loaded, the HAL client calls\n `startRecognition()` to begin detection. Recognition continues to run in the\n background until one of the following events occurs:\n\n 1. A `stopRecognition()` has been called on this model.\n 2. A detection has occurred.\n 3. Detection is aborted due to resource constraints, for example, when a higher priority use case has been initiated.\n\n In the latter two cases, a recognition event is sent via the callback\n interface that is registered by the HAL client upon loading. In all cases,\n after any of these events occur, the detection becomes inactive and no more\n recognition callbacks are allowed.\n\n The same model can be started again at a later time, and this process can be\n repeated as many times as needed.\n3. Finally, an inactive model that is no longer needed is unloaded by the HAL\n client via `unloadModel()`.\n\n| **Note:** When a model is started, the HAL client can call `forceRecognitionEvent()` to generate a forced recognition event. The returned event is similar to a normal recognition event, but has its status field set to `FORCED`. Such recognition events do not automatically stop the recognition. Instead, the model state remains running even after the event has been delivered.\n\nHandle HAL errors\n-----------------\n\nTo ensure reliable and consistent behavior between driver implementations, in\nAndroid 11, any non-success error codes returned from\nthe HAL are treated as programming errors, recovery from which requires\nrestarting the HAL process. This is a last-resort recovery strategy and the\nexpectation is that such cases won't occur in a properly working system.\n| **Note:** Although these errors are being called out as valid in the HAL API documentation, there is ambiguity as to when and under what states these error codes are returned and what the expected error recovery procedure is. Hence, Android 11 mandates stricter conformance of Sound Trigger HAL implementations at runtime than the lower versions of Android."]]