A personalized music generation method and system based on electroencephalogram state
Patent Information
- Application Number
- CN202611516171.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-28
- Publication Date
- 2026-10-30
AI Technical Summary
[0007]本发明的目的在于提供一种基于脑电状态的个性化音乐生成方法及系统,以解决现有脑电音乐技术中多源信息难以有效融合、信号质量波动导致生成跳变、片段间缺乏连续性控制以及缺少闭环个体化适配的问题
本发明实施例提供了一种基于脑电状态的个性化音乐生成方法及系统。其通过将原始生理信号解码为多维用户状态向量,转化为高维情绪表征,为生成式音乐模型提供了细粒度的联合生成条件;在此基础上,引入辅助上下文信息并经冲突消解规则融合编码,实现了脑电状态与用户个体、场景目标等多源信息的有效融合,显著提升了生成内容与用户即时状态的匹配精度;同时,基于脑电特征表示直接计算信号置信度并自适应调整更新权重,有效抑制了伪迹干扰导致的非预期跳变;进一步依据相邻窗口状态变化量动态调整连续性权重,以融合条件向量与连续性条件作为双重生成条件,保证了逐片段生成模式下音乐在调式、和声、音色上的结构连贯性。由此构建的动态控制体系,使脑电状态能够作为高鲁棒性、强连续性的生成条件,稳定驱动个性化音乐内容的实时生成。
Smart Images

Figure CN123016962A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of brain-computer interface and electroencephalogram (EEG) signal processing technology, and more specifically, to a method and system for personalized music generation based on EEG states. Background Technology
[0002] Non-invasive brain-computer interfaces can extract features related to emotional state, arousal, attention, fatigue, tension, and relaxation from electroencephalogram (EEG) signals. Existing EEG music technology typically first determines the emotional category or state level based on EEG features, and then retrieves music from a pre-established music library according to the determined category or level, or adjusts the tempo, volume, and playback order of existing audio.
[0003] In the above methods, EEG signals are mainly used for track selection or playback parameter control, without entering the generation process of melody, harmony, rhythm, timbre, and musical structure. Therefore, different users or different sessions may obtain the same existing content when their states are similar, and there is a lack of content generation-level correspondence between the output music and the current EEG state, making it difficult to achieve truly personalized music generation.
[0004] Generative music models can generate audio waveforms, symbolic music, or musical control sequences based on text, semantic tokens, continuous control parameters, conditional embeddings, or latent space vectors, and possess the ability to jointly generate multiple musical elements. However, EEG state information belongs to physiological and cognitive state representations, which are heterogeneous with the input representations of generative music models. If a single EEG index is directly mapped to tempo or volume, not only is the fine-grained continuous change information of emotional state lost, but it is also difficult to use generative music models to jointly generate melody, harmony, rhythm, timbre, and musical structure.
[0005] To bridge the representation gap between EEG and generative models, some existing technologies attempt to introduce an intermediate semantic layer. For example, by retrieving reinforcement generation (RAG) and large language model (LLM), emotional states are translated into structured music therapy parameter instructions, which then drive the diffusion model to generate music. Although such schemes avoid the reliance on EEG-music pairing data, they still have obvious limitations: (1) Textual translation loses the fine-grained continuous change information of emotional state, and RAG and LLM inference introduce additional computational delays, which is not conducive to real-time intervention scenarios with ultra-low latency; (2) Segment connection usually relies on cross-fade-in and fade-out of fixed duration, and does not model the continuity of music structural elements such as main melody outline, timbre embedding, mode, chord, and beat phase across segments; (3) No confidence threshold mechanism based on multi-dimensional signal quality assessment has been established. When EEG signals are affected by blinking, electromyography, motion artifacts or changes in electrode contact, the generation conditions may change unexpectedly; (4) No conflict resolution mechanism is provided between user state information and multi-source information such as scene goals, individual preferences, and conversation history, making it difficult to generate stable fusion conditions when there is conflict between multi-source information.
[0006] During continuous playback, the user's state changes dynamically with the music. If segments are generated independently each time based on a new state, adjacent segments may be discontinuous in terms of mode, rhythm, harmony, timbre, or musical structure. Furthermore, if EEG signals are affected by blinking, electromyography, movement, changes in electrode contact, or data loss, the generation conditions may also change unexpectedly. Current technology lacks a system that encodes EEG state, user information, conversation history, and playback feedback into music generation conditions, and continuously generates subsequent music segments based on the feedback. Summary of the Invention
[0007] The purpose of this invention is to provide a personalized music generation method and system based on EEG status, in order to solve the problems in existing EEG music technology, such as the difficulty in effectively integrating multi-source information, signal quality fluctuations leading to generation jumps, lack of continuity control between segments, and lack of closed-loop individualized adaptation.
[0008] The embodiments of the present invention are implemented as follows: A personalized music generation method based on brainwave states, comprising: S1. Collect the user's multi-channel EEG signals, extract EEG feature representations and decode them to obtain a multi-dimensional user state vector representing the user's current emotional state; S2. Obtain user state information and auxiliary context information. The auxiliary context information includes at least one of user individual information, scene target information, current session information, and historical feedback information. The user state information and auxiliary context information are fused and encoded using conflict resolution rules to obtain a fusion condition vector. S3. Calculate the confidence level of EEG signals based on EEG feature representation.Q And based on the confidence level of the EEG signals Q Perform multi-level threshold adaptive processing to adaptively adjust the update weights of the fusion condition vector and subsequent generated conditions; S4. Calculate the change in the user state vector between adjacent time windows. D And based on the amount of change D Dynamically adjust the continuity condition weights l C By combining the fusion condition vector and the continuity condition as inputs to the generative music model, personalized music fragments are generated and output.
[0009] Furthermore, in other preferred embodiments of the present invention, in step S2, the auxiliary context information includes user individual information, scene target information, current session information and historical feedback information; the conflict resolution rules include hard constraint filtering and weighted fusion based on preset weights, wherein the weight of the user state source is positively correlated with the confidence level of the EEG signal.
[0010] Furthermore, in other preferred embodiments of the present invention, hard constraint filtering includes auditory safety range constraints, user-disabled content constraints, and content security rule constraints, wherein content security rule constraints have the highest priority; The remaining candidate values filtered by hard constraints are then weighted and fused according to the following normalized weights: The user state source weight is 0.30× Q The weight of individual user information sources is 0.20; the weight of scenario target information sources is 0.25; the weight of current session information sources is 0.15; and the weight of historical feedback information sources is 0.10×. F ; in Q For the confidence level of EEG signals, F Historical feedback is a valid factor; when scene target information and user state information conflict and no security constraints are triggered, the scene target information is used as the directional constraint, and the user state information is only used as the directional constraint. Q When the value is ≥0.60, it participates in fine-grained amplitude adjustment.
[0011] Furthermore, in other preferred embodiments of the present invention, in step S3, the confidence level of the EEG signal... Q The results are calculated using a weighted average of eight dimensions: signal validity, signal amplitude reasonableness, electrooculography artifact persistence, electromyography artifact persistence, contact impedance compliance, spectral characteristic consistency, baseline stability, and effective window ratio. Multi-level threshold adaptive processing includes: when Q When the values are below the confidence threshold and the number of consecutive invalid windows is less than the invalid window threshold, increase the weight of historical valid states and the previous generation conditions. When the number of consecutive invalid windows reaches the invalid window threshold, maintain the current music direction or stop generating conditions based on EEG updates. When the number of consecutive valid windows reaches the valid window threshold, the generation conditions are updated according to the preset step size.
[0012] Furthermore, in other preferred embodiments of the present invention, the confidence level of the eight-dimensional EEG signal... Q The calculation formula is: Q =0.20 r v +0.15 r a +0.10 r e +0.10 r m +0.15 r c +0.10 r s +0.10 r b +0.10 r w ; in, r v For signal validity, r a For the sake of signal amplitude reasonableness, r e For residual electrooculogram artifacts, r m For residual electromyography artifacts, r c For contact resistance compliance, r s For consistency of spectral characteristics, r b For baseline stability, r w This represents the effective window ratio.
[0013] Furthermore, in other preferred embodiments of the present invention, in step S4, the change amount D With continuity condition weights l C The relationship is: when D When less than or equal to the low change threshold, l C Take the strong continuity weight to represent strong continuity; when D When it exceeds the high change threshold, l C Weigh the weak continuity and gradually change the musical elements in the transition segments; when D When the value is between the low change threshold and the second preset threshold, l C Linear interpolation between strong and weak continuity weights.
[0014] Furthermore, in other preferred embodiments of the present invention, in step S4, the continuity conditions include: main melody outline features, timbre embedding features, and mode, chord, and beat phase features; The main melody contour features are obtained by half-sampling the fundamental frequency sequence of the current segment and resampling it for equal duration; the timbre embedding features are obtained by extracting the tail audio spectrum of the current segment through a convolutional neural network, time pooling, and L2 normalization.
[0015] Furthermore, in other preferred embodiments of the present invention, it further includes: S5. Collect the user's EEG signal again after the music clip is played, calculate the feedback effect between the effective window set before and after the playback, and update the user's individualized adaptation parameters using at least one of the following methods: exponential moving average, constrained gradient update, contextual multi-armed gambler, and parameter efficient fine-tuning. The generated identifier is associated with user state snapshots, session identifiers, generated seeds, and model versions for storage, so that the generated content can be traced back to a specific user and a specific time.
[0016] Furthermore, in other preferred embodiments of the present invention, step S1, extracting EEG feature representation, includes: The raw EEG signal is subjected to bandpass filtering, independent component analysis for artifact removal, segmentation and frequency band decomposition according to a preset time window, and extraction of differential entropy features of each frequency band to generate a standardized spatiotemporal frequency feature tensor. Decoding yields a multidimensional user state vector, including: A hybrid architecture combining graph neural networks and temporal modeling is used to decode the emotional state of spatiotemporal frequency feature tensors and output a multidimensional user state vector.
[0017] A personalized music generation system based on brainwave states, comprising: The EEG signal acquisition and preprocessing module is used to acquire the user's multi-channel EEG signals and perform preprocessing and feature extraction to generate a standardized spatiotemporal frequency feature tensor. The emotion recognition module is used to decode the emotional state of the spatiotemporal frequency feature tensor and output a multidimensional user state vector. The fusion and conflict resolution module is used to acquire user state information and auxiliary context information, and to fuse and encode the user state information and auxiliary context information through conflict resolution rules to obtain a fusion condition vector. The signal confidence and continuity control module is used to calculate the confidence level of EEG signals based on the spatiotemporal frequency feature tensor. Q It also performs multi-level threshold adaptive processing, calculates the change D of the user state vector in adjacent time windows, and dynamically adjusts the continuity condition weights accordingly. l C ; The generative music model module is used to jointly generate and output personalized music fragments by using fusion condition vectors and continuity conditions as dual generation conditions for melody, harmony, rhythm, timbre and music structure.
[0018] The beneficial effects of the embodiments of the present invention are: This invention provides a personalized music generation method and system based on brainwave state. It decodes raw physiological signals into multi-dimensional user state vectors, transforming them into high-dimensional emotion representations, providing fine-grained joint generation conditions for generative music models. Based on this, auxiliary contextual information is introduced and fused through conflict resolution rules, achieving effective fusion of brainwave state with multi-source information such as individual user characteristics and scene objectives, significantly improving the matching accuracy between generated content and the user's real-time state. Simultaneously, it directly calculates signal confidence based on brainwave feature representations and adaptively adjusts and updates weights, effectively suppressing unexpected jumps caused by artifact interference. Furthermore, it dynamically adjusts continuity weights based on changes in adjacent window states, using the fusion condition vector and continuity conditions as dual generation conditions to ensure the structural coherence of music in mode, harmony, and timbre in the segment-by-segment generation mode. The resulting dynamic control system enables brainwave state to serve as a highly robust and continuous generation condition, stably driving the real-time generation of personalized music content. Attached Figure Description
[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A flowchart illustrating the personalized music generation method based on EEG status provided in an embodiment of the present invention; Figure 2 This is a schematic diagram illustrating how user status information and auxiliary information, provided in an embodiment of the present invention, form the conditions for music generation. Figure 3 This is a schematic diagram illustrating the generation and processing of music content using the generative music model provided in an embodiment of the present invention. Figure 4This is a closed-loop diagram illustrating the segment-based EEG acquisition, music generation, playback, and feedback update provided in an embodiment of the present invention. Figure 5 This is a schematic diagram illustrating the deployment of wearable brain-computer interface devices, mobile terminals or edge devices, and authorized cloud services provided in embodiments of the present invention. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to represent selected embodiments of the invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] The features and performance of the present invention will be further described in detail below with reference to embodiments.
[0023] Example
[0024] This embodiment provides a personalized music generation method based on brainwave states, referring to... Figure 1 As shown, it includes: S1. Collect the user's multi-channel EEG signals, extract EEG feature representations and decode them to obtain a multi-dimensional user state vector representing the user's current emotional state.
[0025] Specifically, the brain-computer interface includes at least one non-invasive EEG electrode and sampling circuitry. The electrode can be placed on the forehead, ear, or scalp, and the sampling rate can be configured to 250Hz or 500Hz. As a preferred extension, the system can also acquire at least one of heart rate, heart rate variability, skin conductance, respiration, eye movement, body movement, or environmental information, and synchronize it with the EEG signal using a unified timestamp to form multimodal physiological and contextual features.
[0026] The specific implementation of extracting EEG feature representations includes: The raw EEG signal is sequentially subjected to bandpass filtering (e.g., 1-50Hz), independent component analysis (ICA) artifact removal, segmentation according to preset time windows (e.g., 4 seconds duration, with adjacent windows overlapping by 2 seconds), and frequency band decomposition (e.g., divided into...). d , i , α ,β , c Five frequency bands are used to extract the differential entropy features of each band, generating a standardized spatiotemporal frequency feature tensor, which is the EEG feature representation in this step. The EEG features may also include the absolute power, relative power, or spectral entropy of each frequency band, as well as one or more of the following indices: band ratio, frontal asymmetry, channel correlation, coherence, and phase synchronization. To eliminate individual baseline differences, EEG features can be individually normalized using a rolling baseline formed by a conversational baseline or a historical effective window. Through frequency band decomposition and individual normalization, the influence of individual differences and conversation drift on state decoding is suppressed, making the features of the same user at different times and different users in the same emotional state comparable, thus improving the cross-conversation stability and cross-subject generalization ability of emotional state decoding.
[0027] The specific implementation of decoding to obtain the multidimensional user state vector includes: A hybrid architecture combining graph neural networks (GNNs) and temporal modeling is used to decode emotional states from spatiotemporal frequency feature tensors. The GNN portion employs a dual adjacency matrix (functional connectivity adjacency matrix and physical distance adjacency matrix) to model the spatial relationships between channels, while the temporal modeling portion uses a Transformer encoder to capture long-range temporal dependencies. The final output is a multidimensional user state vector representing the user's current emotional state, such as a two-dimensional valence-arousal vector or a higher-dimensional emotional state representation. This hybrid architecture simultaneously captures the spatial topological relationships and temporal dynamics of EEG signals. Compared to single fully connected networks or recurrent networks, it can more fully exploit the functional connectivity information between EEG channels, thus outputting a more accurate and fine-grained multidimensional emotional state representation, providing high-quality conditional input for subsequent generative music models.
[0028] The extracted spatiotemporal frequency feature tensor (EEG feature representation) will be used in the subsequent S3 step to calculate the confidence level of the EEG signal. Q The data foundation.
[0029] Furthermore, the personalized music generation method based on EEG state provided in this embodiment refers to... Figure 2 As shown, it also includes: S2. Obtain user state information and auxiliary context information. The auxiliary context information includes at least one of user individual information, scene target information, current session information, and historical feedback information. The user state information and auxiliary context information are fused and encoded through conflict resolution rules to obtain a fusion condition vector.
[0030] In practical implementation, the user state information is the multi-dimensional user state vector decoded in S1. The specific content of the auxiliary context information is as follows: individual user information includes music style preference, timbre preference, prohibited content, auditory safety range, and individual conditional embedding; scene goal information includes intervention goals such as relaxation, focus, bedtime, meditation, or mild activation; current session information includes session identifier, time information, environmental information, structural summary of the previous music segment, and current segment position; historical feedback information includes historical state changes, user interaction information, and generated music summaries.
[0031] As a preferred implementation, the auxiliary context information includes all four types of information mentioned above, that is, the user state information and all four types of auxiliary context information are fused together.
[0032] By introducing auxiliary contextual information and fusing it with EEG state information, the limitations of existing technologies that rely solely on a single EEG state or simple text commands are overcome. This allows the generated fusion condition vector to integrate multi-dimensional information such as the user's immediate emotions, long-term preferences, scene goals, conversational context, and historical feedback, significantly improving the matching accuracy between the generated music and the user's immediate state and long-term preferences. The conflict resolution rules ensure that stable and secure fusion conditions can still be output even when there is directional conflict among the multi-source information.
[0033] In practical implementation, the conditional encoder performs source encoding on the five source information: for the first... i Normalized input of the source x i splicing source type embedding e i Then, it is obtained through the corresponding source coding network. h i = MLP ( LayerNorm ([ x i ; e i Each source coding network can be a two-layer fully connected network (first layer dimension 256, activation function GELU, second layer output dimension 128).
[0034] User state sources are weighted by confidence level: h '1= Q · h 1+(1- Q )· h valid ; in h validThe user state source of the most recent high-confidence window is embedded, so that when the signal quality deteriorates, it will automatically fall back to the historical valid state, avoiding artifacts from polluting the fusion conditions. Q The confidence level of the EEG signal calculated based on the EEG feature representation in the subsequent S3 step is directly used here for weighting. h valid The update timing and initial value settings are as follows: After the session begins, the user state source embedding obtained by decoding in the first time window is used. h 1 As h valid The initial value; thereafter, after each time window is processed, if the confidence level of the EEG signal in that window is... Q If the confidence level is not lower than the threshold (preferably 0.60), then the user state source of the window is embedded. h 1 Updated to new h valid If the window Q If it is below the confidence threshold, then h valid It remains unchanged, still embedded as the user state source of the most recent high-confidence window.
[0035] To ensure that the fusion conditions accurately match the music generation requirements, a mapping relationship is established between various dimensions of user state and music control parameters: emotional state controls the emotional direction, modal tendency, and harmonic timbre; arousal controls tempo, rhythm density, and event density; attention controls repetitive structures and melodic complexity; fatigue controls rhythmic clarity, spectral energy, and stimulus intensity; and tension and relaxation control harmonic tension, abruptness, and envelope variation. Based on this, the conditional encoder converts user state information into emotional semantic tokens, music style tokens, continuous music control parameters, conditional embeddings, latent space vectors, negative constraints, or combinations thereof. Continuous music control parameters include at least one of tempo, rhythm density, event density, modal tendency, harmonic tension, melodic complexity, timbre vector, spectral envelope, spatialization intensity, and segment duration. This mapping relationship transforms abstract physiological and cognitive states into computable music control parameters, enabling generative music models to jointly generate multiple music elements based on continuous changes in emotional state, rather than simply mapping a single EEG indicator to tempo or volume. This achieves fine-grained, multi-element control of music content by EEG state.
[0036] The conflict resolution rule, in its implementation, includes two sub-steps: hard constraint filtering and weighted fusion based on preset weights. The weights of the user state source and the confidence level of the EEG signal are used in the process. Q Positive correlation. Specifically as follows: Hard constraint filtering: The rule mapping unit converts prohibited content, auditory safety range, music parameter boundaries, necessary conditions for scene targets, and continuity requirements of the previous segment into rule vectors. h R And the corresponding set of hard constraints, among which auditory safety range, user-disabled content, and content security rules have the highest priority, and candidate values that violate any hard constraint are deleted.
[0037] Weighted fusion: For the remaining candidate values filtered by hard constraints, calculate the weight of each source: the weight of the user state source is 0.30 × Q The weight of individual user information sources is 0.20; the weight of scenario target information sources is 0.25; the weight of current session information sources is 0.15; and the weight of historical feedback information sources is 0.10×. F .in Q For the confidence level of EEG signals, F Historical feedback is a valid factor; when scene target information and user state information conflict and no security constraints are triggered, the scene target information is used as the directional constraint, and the user state information is only used as the directional constraint. Q When the value is ≥0.60, it participates in fine-grained amplitude adjustment.
[0038] Furthermore, embedding scene targets with h The concatenated vector of '1' is the query vector. q The key vectors obtained by projecting the five source embeddings respectively k i Sum value vector v i Perform scaling dot product attention: ; Where d is the dimension of the key vector. b i For source type bias.
[0039] The scaled dot product attention mechanism can adaptively learn the importance weights of each source of information in the current context. Compared with linear fusion with fixed weights, it captures the complex dependencies between multiple sources of information more flexibly, and is especially suitable for scenarios where scene goals and user states need to be dynamically balanced.
[0040] Gated fusion units fuse attention vectors h A Regular vectors h R and continuity condition vector h C After concatenation, input into at least two fully connected layers of network to obtain neural fusion vectors. h N ;according to We obtain three gating coefficients, and the final condition vector is:h = g 1 h A + g 2 h R + g 3 h N Then, it is converted into music generation conditions through multiple output heads. Among them, W g Here is the weight matrix of the gated network. b g is the bias vector of the gated network.
[0041] The gating fusion mechanism combines the soft constraints of attention fusion, the hard constraints of regular vectors, and the nonlinear expressive power of neural networks. While ensuring that the generation conditions meet the requirements of safety and continuity, it retains the model's ability to fit complex mapping relationships, thereby outputting a fusion condition vector that balances safety, continuity, and personalization.
[0042] Furthermore, the personalized music generation method based on EEG state provided in this embodiment also includes: S3. Calculate the confidence level of EEG signals based on EEG feature representation. Q And based on the confidence level of the EEG signals Q Perform multi-level threshold adaptive processing to adaptively adjust the update weights of the fusion condition vector and subsequent generated conditions.
[0043] In practical implementation, based on the spatiotemporal frequency feature tensor (EEG feature representation) extracted from S1, the quality indicators for each time window are normalized to obtain eight-dimensional sub-confidence scores with values ranging from 0 to 1: r v Signal validity (the proportion of effective channels to the total number of channels); r a To ensure the reasonableness of the signal amplitude (which can be obtained from the complement of the proportion of abnormal samples); r e The residual value of electrooculography artifacts (which can be obtained from the complement of the energy ratio of the abnormal frequency band); r m The residual value of electromyography artifacts (which can be obtained from the complement of the energy ratio of the abnormal frequency band); r c For contact resistance compliance; r s For spectral characteristic consistency (which can be obtained from the complement of the energy ratio of the anomalous frequency band); r b For baseline stability; r w This represents the effective window ratio.
[0044] Confidence of EEG signals Q The calculation formula is: Q =0.20 r v +0.15 r a +0.10 r e +0.10 r m +0.15 r c +0.10 r s +0.10 r b +0.10 r w .
[0045] Furthermore, the multi-level threshold adaptive processing specifically includes: (a) when Q When the confidence level is below the threshold (preferably 0.60) and the number of consecutive invalid windows is less than the invalid window threshold, the weights of historical valid states and previous generation conditions are increased. In S2 fusion coding, this is reflected as follows: h '1= Q · h 1+(1- Q )· h valid middle h valid Automatic weight boosting; (b) When the number of consecutive invalid windows reaches the invalid window threshold (preferably 3), maintain the current music direction or stop generating conditions based on EEG updates; (c) When the number of consecutive valid windows reaches the valid window threshold (preferably 3), the generation conditions are updated according to a preset step size (e.g., restoring 10% of the EEG condition weight each time).
[0046] The confidence threshold, invalid window threshold, and valid window threshold mentioned above can be equivalently calibrated under different sampling rates or window lengths.
[0047] The three-level threshold (instantaneous quality assessment, continuous invalidation, and continuous valid recovery) combined with the historical state regression and progressive recovery mechanism effectively suppresses unexpected jumps in EEG signals caused by blinking, electromyography, motion artifacts, or changes in electrode contact. This avoids the problem of sudden changes in music parameters caused by signal artifacts in existing technologies, and significantly improves auditory stability and system robustness. The progressive recovery design also avoids music jitter caused by frequent switching between updating and maintaining when signal quality fluctuates.
[0048] Furthermore, the personalized music generation method based on EEG state provided in this embodiment refers to... Figure 3 As shown, it also includes: S4. Calculate the change in the user state vector between adjacent time windows. D And based on the amount of change D Dynamically adjust the continuity condition weights l C By combining the fusion condition vector and the continuity condition as inputs to the generative music model, personalized music fragments are generated and output.
[0049] In practical implementation, the amount of change D The degree of difference between user state vectors in adjacent time windows can be measured by cosine distance or Euclidean distance, or by weighting at least two of the following: changes in emotional state, changes in arousal, changes in attention, changes in fatigue, changes in tension, and changes in relaxation.
[0050] D and l C The specific relationship is as follows: when D When the value is less than or equal to the low change threshold (preferably 0.15), l C By assigning a strong continuity weight (preferably 0.80), the system tends to keep the current musical elements unchanged. when D When the value is greater than the high change threshold (preferably 0.35), l C A weak continuity weight (preferably 0.30) is applied, and the tempo, mode, harmonic tension, rhythm density, or timbre vector is gradually changed in at least one transition segment; when D When the change is between the low change threshold and the high change threshold, l C Linear interpolation is performed between strongly continuous weights and weakly continuous weights, using the following formula: l C =0.80-( D -0.15)×0.50 / 0.20.
[0051] The condition vector used to generate the next segment is: C next = l C · h C +(1- l C )· h ,in hThis is the fusion condition vector corresponding to the current state. h C It is a continuity condition vector.
[0052] The above uses state change quantities D Driven continuity weights l C The dynamic adjustment mechanism ensures a high degree of continuity of musical elements when the user's state is stable (avoiding unnecessary style switching), and allows for gradual transitions through transitional segments when the state changes significantly (avoiding abrupt changes). This fundamentally solves the problems of disjointed musical structure caused by abrupt mode transitions, harmonic breaks, and abrupt changes in timbre resulting from independent generation of each segment in existing technologies. The linear interpolation design ensures smooth changes in the degree of continuity, further enhancing the auditory experience.
[0053] Continuity conditions h C The construction specifically includes: Main melody outline characteristics: by applying a constant to the end audio of the current segment Q The time-frequency representation is obtained by transform or short-time Fourier transform. The Viterbi path search is used on the candidate fundamental frequency trajectory to obtain the main melody fundamental frequency sequence. The fundamental frequency sequence is converted to semitone values relative to the current mode's main volume and resampled into 16 nodes at equal time intervals. The intervals and durations of adjacent nodes form the main melody contour vector. Timbre embedding features: The tail audio is divided into frames with a frame length of 25 milliseconds and a frame shift of 10 milliseconds to form a 128-dimensional log-Mel spectrum; the log-Mel spectrum is input into a four-layer convolutional network containing 32, 64, 128, and 256 channels, and after global temporal pooling and 128-dimensional linear projection, it is normalized by L2 to obtain the 128-dimensional timbre embedding. Mode, chord, and beat phase features: Extract at least one of the following features from the current segment: mode, chord progression, tempo, beat phase, spectral envelope, segment position, or latent audio representation at the end.
[0054] The aforementioned main melody contour vector, 128-dimensional timbre embedding and mode, chord, and rhythmic phase features belong to different types and dimensions of features. To obtain a single continuous conditional vector... h C In practice, the main melody contour vector, 128-dimensional timbre embedding, and mode, chord, and beat phase features are mapped to feature vectors of a unified dimension (e.g., 128-dimensional) through corresponding fully connected projection layers. The mapped feature vectors are then concatenated and input into a fully connected layer to be mapped into a single continuous condition vector with the same dimension as the fusion condition vector. h C , used for C next =λC ·h C +(1-l C )·h The calculation.
[0055] Adjacent segments are connected through beat alignment, chord compatibility checks, phase alignment, or crossfading to ensure auditory coherence.
[0056] The continuity condition of the three elements of main melody outline, timbre embedding and mode / chord / beat phase constrains the connection between adjacent segments from three levels: melody direction, timbre texture and harmonic rhythm. Compared with existing technologies that only rely on cross-fade-in and fade-out of fixed duration, it can fundamentally ensure the structural coherence and unity of music across segments. The Viterbi path search and equal-duration resampling main melody extraction method, as well as the log-Mel spectrum and multi-layer convolution timbre encoding method, all provide stable and computable quantitative representation of the continuity constraint.
[0057] After obtaining the fusion condition vector and continuity condition, the fusion condition vector and continuity condition are jointly input into the generative music model. The generative music model may include Transformer, diffusion model, autoregressive model, variational autoencoder, generative adversarial network, or a combination thereof. The model can directly generate audio waveforms or multi-track audio, or it can generate MIDI sequences, note events, audio tokens, multi-track structures, music control sequences, or latent variables, which are then rendered into audio by an audio engine, synthesizer, or neural audio decoder. During generation, the generative music model uses at least one of the following: user profile summary, session identifier, user state snapshot, generation seed, and model version, to associate the generated content with the current user state and the current session. The system constructs a generation identifier based on at least three of the following: user profile summary, user state snapshot, session identifier, generation seed, music generation condition summary, and model version, and stores the generation identifier in association with the music content or generation record.
[0058] By using fusion condition vectors and continuity conditions as dual generation conditions, the generative music model can simultaneously respond to the personalized needs driven by EEG state and the structural constraints of cross-segment continuity. It achieves the joint generation of multiple elements such as melody, harmony, rhythm, timbre and music structure. The output music content is newly generated in the current session, rather than content retrieved or adapted from the existing music library. This establishes a correspondence between content generation levels that are not present in existing content when states are similar and output the same content.
[0059] Furthermore, the personalized music generation method based on EEG state provided in this embodiment refers to... Figure 4 As shown, it also includes: S5. After the music clip is played, collect the user's EEG signal again and calculate the feedback effect between the effective window sets before and after playback. The feedback effect is calculated based on at least two changes in emotional state, arousal, attention, fatigue, tension, and relaxation between the effective window sets before and after feedback, as well as at least one interaction information from the user skipping, volume adjustment, liking, disliking, or task completion. The calculation direction is determined by the scene objective.
[0060] By collecting EEG signals again after playback and calculating the feedback effect, a complete closed loop of EEG perception—music generation—playback—feedback evaluation—regeneration was established, enabling the generation conditions of subsequent music segments to be adaptively adjusted according to the user's real-time response. The feedback evaluation method, which combines multidimensional state changes with interactive information, can more comprehensively reflect the intervention effect compared to relying solely on a single emotion indicator.
[0061] Optionally, the user's individualized adaptation parameters are updated using at least one of the following methods: exponential moving average, constrained gradient update, contextual multi-armed gambler, and parameter-efficient fine-tuning (such as LoRA), including the generation conditions of subsequent music segments, conditional encoding weights, sampling parameters, or individualized adaptation parameters of the generative music model.
[0062] At the same time, the generated identifier is associated with user state snapshots, session identifiers, generation seeds, and model versions for storage, so that the generated content can be traced back to a specific user and a specific time.
[0063] As a preferred extension, music generation conditions may also include breathing guidance conditions, generating rhythmic events, volume envelopes, cue tracks, or music segment structures corresponding to inhalation duration, exhalation duration, pause duration, or target breathing frequency. Breathing guidance conditions couple music rhythm with the user's breathing rhythm, further expanding the application scenarios of EEG-driven music intervention, making it suitable for scenarios requiring rhythmic guidance, such as breathing training and relaxation meditation.
[0064] Before playback, various safety constraints can be applied to the music content, including peak value limits, overall loudness limits, frequency energy limits, unit time parameter variation limits, content security reviews, and user-disabled content reviews. If these constraints are not met, resampling, partial rewriting, parameter correction, or reverting to safe music generation conditions can be performed. This multi-level safety constraint system ensures that the output audio remains within an auditory safety range while maintaining the personalization and continuity of the music, avoiding adverse effects on the user's hearing or emotions caused by extreme parameter combinations.
[0065] Furthermore, this embodiment also provides a personalized music generation system based on brainwave states, which includes: The EEG signal acquisition and preprocessing module is used to acquire the user's multi-channel EEG signals and perform preprocessing and feature extraction to generate a standardized spatiotemporal frequency feature tensor. The emotion recognition module is used to decode the emotional state of the spatiotemporal frequency feature tensor and output a multidimensional user state vector. The fusion and conflict resolution module is used to acquire user state information and auxiliary context information, and to fuse and encode the user state information and auxiliary context information through conflict resolution rules to obtain a fusion condition vector. The signal confidence and continuity control module is used to calculate the confidence level of EEG signals based on the spatiotemporal frequency feature tensor. Q It also performs multi-level threshold adaptive processing and calculates the change in user state vectors between adjacent time windows. D The continuity condition weights are then dynamically adjusted accordingly. l C ; The generative music model module is used to jointly generate and output personalized music fragments by using fusion condition vectors and continuity conditions as dual generation conditions for melody, harmony, rhythm, timbre and music structure.
[0066] The aforementioned system employs a modular architecture design, decoupling core functions such as EEG signal acquisition and preprocessing, emotion recognition, fusion and conflict resolution, signal confidence and continuity control, and generative music models into independent modules. Each module can be flexibly deployed on wearable devices, mobile terminals, edge devices, or authorized cloud services. For example, ... Figure 5 As shown, the brain-computer interface signal acquisition module and basic quality assessment module can be set up in wearable devices; the state representation module, music generation condition construction module, audio playback module, and feedback evaluation module can be set up in mobile terminals or edge devices; and the generative music model can be set up in mobile terminals, edge devices, or authorized cloud services. When the network is unavailable, the mobile terminal can call the local generative music model, continue to use the already generated music segments, or generate safe transition segments. This approach ensures real-time performance while also considering the reasonable allocation of computing resources and the scalability of the system. The distributed deployment method of end-edge-cloud also enables the system to call the local model or generate safe transition segments when the network is unavailable, improving system availability.
[0067] In summary, this invention provides a personalized music generation method and system based on EEG states. It decodes raw physiological signals into multi-dimensional user state vectors, transforming them into high-dimensional emotion representations, providing fine-grained joint generation conditions for generative music models. Furthermore, by introducing auxiliary contextual information and fusing it with conflict resolution rules, it achieves effective fusion of EEG states with multi-source information such as individual users and scene objectives, significantly improving the matching accuracy between generated content and the user's immediate state. Simultaneously, by directly calculating signal confidence based on EEG feature representations and adaptively adjusting and updating weights, it effectively suppresses unexpected jumps caused by artifact interference. Moreover, by dynamically adjusting continuity weights based on the changes in adjacent window states, using the fusion condition vector and continuity conditions as dual generation conditions, it ensures the structural coherence of music in terms of mode, harmony, and timbre in the segment-by-segment generation mode. The resulting dynamic control system enables EEG states to serve as highly robust and highly continuous generation conditions, stably driving the real-time generation of personalized music content.
[0068] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A personalized music generation method based on brainwave states, characterized in that, include: S1. Collect the user's multi-channel EEG signals, extract EEG feature representations and decode them to obtain a multi-dimensional user state vector representing the user's current emotional state; S2. Obtain user state information and auxiliary context information, wherein the auxiliary context information includes at least one of user individual information, scene target information, current session information and historical feedback information; fuse the user state information and the auxiliary context information through conflict resolution rules to obtain a fusion condition vector. S3. Calculate the confidence level of the EEG signal based on the EEG feature representation. Q And based on the confidence level of the said electroencephalogram (EEG) signals Q Perform multi-level threshold adaptive processing to adaptively adjust the updated weights of the fusion condition vector and subsequent generated conditions; S4. Calculate the change in the user state vector between adjacent time windows. D And based on the amount of change D Dynamically adjust the continuity condition weights λ C The fusion condition vector and the continuity condition are combined and input into the generative music model to generate and output personalized music fragments.
2. The personalized music generation method according to claim 1, characterized in that, In step S2, the auxiliary context information includes user individual information, scene target information, current session information, and historical feedback information; the conflict resolution rules include hard constraint filtering and weighted fusion based on preset weights, wherein the weight of the user state source is positively correlated with the confidence level of the EEG signal.
3. The personalized music generation method according to claim 2, characterized in that, The hard constraint filtering includes auditory safety range constraints, user-disabled content constraints, and content security rule constraints, wherein the content security rule constraints have the highest priority. The remaining candidate values filtered by hard constraints are then weighted and fused according to the following normalized weights: The user state source weight is 0.30× Q The weight of individual user information sources is 0.20; the weight of scenario target information sources is 0.25; the weight of current session information sources is 0.15; and the weight of historical feedback information sources is 0.10×. F ; in Q The confidence level of the EEG signal. F Effective factors for historical feedback; When scene target information and user state information conflict and no security constraints are triggered, the scene target information is used as the directional constraint, and the user state information is only used as the directional constraint. Q When the value is ≥0.60, it participates in fine-grained amplitude adjustment.
4. The personalized music generation method according to claim 1, characterized in that, In step S3, the confidence level of the EEG signal Q The multi-level threshold adaptive processing is calculated by weighting eight dimensions: signal validity, signal amplitude reasonableness, electrooculography artifact persistence, electromyography artifact persistence, contact impedance compliance, spectral characteristic consistency, baseline stability, and effective window ratio. when Q When the values are below the confidence threshold and the number of consecutive invalid windows is less than the invalid window threshold, increase the weight of historical valid states and the previous generation conditions. When the number of consecutive invalid windows reaches the invalid window threshold, maintain the current music direction or stop generating conditions based on EEG updates. When the number of consecutive valid windows reaches the valid window threshold, the generation conditions are updated according to the preset step size.
5. The personalized music generation method according to claim 4, characterized in that, The confidence level of the EEG signal Q The calculation formula is: Q =0.20 r v +0.15 r a +0.10 r e +0.10 r m +0.15 r c +0.10 r s +0.10 r b +0.10 r w ; in, r v For signal validity, r a For the sake of signal amplitude reasonableness, r e For residual electrooculogram artifacts, r m For residual electromyography artifacts, r c For contact resistance compliance, r s For consistency of spectral characteristics, r b For baseline stability, r w This represents the effective window ratio.
6. The personalized music generation method according to claim 1, characterized in that, In step S4, the change amount D With continuity condition weights λ C The relationship is: when D When less than or equal to the low change threshold, λ C Take the strong continuity weight to represent strong continuity; when D When it exceeds the high change threshold, λ C Weigh the weak continuity and gradually change the musical elements in the transition segments; when D When the value is between the low change threshold and the second preset threshold, λ C Linear interpolation between strong and weak continuity weights.
7. The personalized music generation method according to claim 6, characterized in that, In step S4, the continuity conditions include: main melody outline features, timbre embedding features, and mode, chord, and meter phase features; The main melody contour feature is obtained by half-sampling the fundamental frequency sequence of the current segment and resampling it for equal duration; the timbre embedding feature is obtained by extracting the tail audio spectrum of the current segment through a convolutional neural network, time pooling, and L2 normalization.
8. The personalized music generation method according to claim 1, characterized in that, Also includes: S5. After the music clip is played, the user's EEG signal is collected again, the feedback effect between the effective window set before and after the playback is calculated, and the user's individualized adaptation parameters are updated using at least one of the following methods: exponential moving average, constrained gradient update, contextual multi-armed gambler, and parameter efficient fine-tuning. The generated identifier is associated with user state snapshots, session identifiers, generated seeds, and model versions for storage, so that the generated content can be traced back to a specific user and a specific time.
9. The personalized music generation method according to claim 1, characterized in that, In step S1, the extraction of EEG feature representation includes: The raw EEG signal is subjected to bandpass filtering, independent component analysis for artifact removal, segmentation and frequency band decomposition according to a preset time window, and extraction of differential entropy features of each frequency band to generate a standardized spatiotemporal frequency feature tensor. The decoding yields a multi-dimensional user state vector, including: A hybrid architecture combining graph neural networks and temporal modeling is used to decode the emotional state of the spatiotemporal frequency feature tensor and output the multidimensional user state vector.
10. A personalized music generation system based on brainwave states, characterized in that, include: The EEG signal acquisition and preprocessing module is used to acquire the user's multi-channel EEG signals and perform preprocessing and feature extraction to generate a standardized spatiotemporal frequency feature tensor. The emotion recognition module is used to decode the emotional state of the spatiotemporal frequency feature tensor and output a multidimensional user state vector. The fusion and conflict resolution module is used to acquire user state information and auxiliary context information, and to fuse and encode the user state information and the auxiliary context information through conflict resolution rules to obtain a fusion condition vector. The signal confidence and continuity control module is used to calculate the confidence level of the EEG signal based on the spatiotemporal frequency feature tensor. Q It also performs multi-level threshold adaptive processing, calculates the change D of the user state vector in adjacent time windows, and dynamically adjusts the continuity condition weights accordingly. λ C ; The generative music model module is used to jointly generate and output personalized music fragments by using the fusion condition vector and the continuity condition as dual generation conditions for melody, harmony, rhythm, timbre and music structure.
