Text positioning method and device, electronic equipment and storage medium

By obtaining the clip to be read and the content displayed on the current page in the e-reader, determining the intersection position, and marking the target area when reading, the problem of users positioning the reading content in real time is solved, and convenient text content viewing is achieved.

CN119862266APending Publication Date: 2025-04-22BEIJING QIYI CENTURY SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411786869.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-06
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

When users listen to audiobooks, it is difficult for users to locate the corresponding position of the reading content in the text in real time, and it is impossible to easily switch to view the text content.

Method used

By obtaining the fragment to be read aloud and the content displayed on the current page of the target text, determine whether there is an intersection between the fragment to be read aloud and the content displayed on the current page, and in the case of intersection, determine the intersection position of the fragment to be read aloud and the text line. Finally, when the electronic reader reads the fragment to be read aloud, mark the target area to achieve real-time positioning.

Benefits of technology

It realizes the real-time location of the content of the fragment to be read in the text content displayed by the electronic reader, so that users can understand the text content corresponding to the current reading content in real time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119862266A_ABST
    Figure CN119862266A_ABST
Patent Text Reader

Abstract

The invention provides a text positioning method and device, electronic equipment and a storage medium. The method comprises the steps of obtaining a to-be-read fragment corresponding to a target text, and obtaining current page display content corresponding to the target text; determining whether an intersection exists between the to-be-read fragment and the current page display content or not; under the condition that the segment to be read and the current page display content have an intersection, for each text line in the current page, determining whether the segment to be read and the text line have an intersection; under the condition that the to-be-read fragment and the text line have an intersection, determining a starting position and an ending position of the intersection of the to-be-read fragment and the text line, and determining a target area based on the starting position and the ending position; and in the process of reading the to-be-read fragment by the electronic reader, marking the target area so as to realize positioning of the to-be-read fragment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of text processing technology, and in particular to a text positioning method, device, electronic device and storage medium. Background Art

[0002] With the popularization of electronic products and the development of computer technology, more and more users use portable electronic reading devices (mobile phones, readers, tablet computers, etc.) to read e-books. Since electronic reading devices generally have audio playback functions, audio books have also emerged, such as audio news, audio novels, children's audio books, and so on.

[0003] When listening to audiobooks, users have the need to match the content read aloud by the electronic reading device with the text content displayed by the electronic reading device, that is, the need to locate the read content in the text content. For example, some users are accustomed to watching while listening, or some users want to switch to watching the text content after listening to a piece of content.

[0004] Therefore, there is an urgent need for a technical solution that can perform text positioning in real time based on the read content. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a text positioning method, device, electronic device and storage medium to achieve the effect of real-time text positioning according to the reading content. The specific technical solution is as follows:

[0006] In a first aspect, the present application provides a text positioning method, comprising:

[0007] Obtaining a segment to be read aloud corresponding to the target text, and obtaining the current page display content corresponding to the target text, wherein the current page display content is used to represent a portion of the target text displayed on the current page of the electronic reader;

[0008] Determine whether the segment to be read aloud and the content displayed on the current page have an intersection;

[0009] In the case that the segment to be read aloud and the displayed content of the current page have an intersection, for each text line in the current page, determining whether the segment to be read aloud and the text line have an intersection;

[0010] In the case where the segment to be read aloud and the text line have an intersection, determining a starting position and an ending position of the intersection of the segment to be read aloud and the text line, and determining a target area based on the starting position and the ending position;

[0011] In the process of the electronic reader reading aloud the segment to be read aloud, the target area is marked to achieve the positioning of the segment to be read aloud.

[0012] In a possible implementation manner, determining whether the segment to be read aloud has an intersection with the content displayed on the current page includes:

[0013] Obtaining a segment first character position index and a segment last character position index corresponding to the segment to be read aloud, wherein the segment first character position index is the position index of the first character in the segment to be read aloud in the target text, and the segment last character position index is the position index of the last character in the segment to be read aloud in the target text;

[0014] Obtain the page first character position index and page last character position index corresponding to the current page display content, wherein the page first character position index is the position index of the first character in the current page display content in the target text, and the page last character position index is the position index of the last character in the current page display content in the target text;

[0015] If the page first character position index is smaller than the segment last character position index, and the page last character position index is larger than the segment first character position index, it is determined that the segment to be read aloud has an intersection with the current page display content.

[0016] In a possible implementation manner, determining whether the segment to be read aloud and the text line have an intersection includes:

[0017] Obtain the first character position index and the last character position index corresponding to the text line, wherein the first character position index is the position index of the first character in the text line in the target text, and the last character position index is the position index of the last character in the text line in the target text;

[0018] If the line end character position index is greater than or equal to the segment first character position index, and the line first character position index is less than or equal to the segment end character position index, it is determined that the segment to be read aloud has an intersection with the text.

[0019] In a possible implementation manner, determining the starting position and the ending position of the intersection of the segment to be read aloud and the text line includes:

[0020] Determine a maximum value among the first character position index of the row and the first character position index of the segment, and determine the position indicated by the position index corresponding to the maximum value as the starting position;

[0021] A minimum value is determined between the line end character position index and the segment end character position index, and a position indicated by the position index corresponding to the minimum value is determined as the end position.

[0022] In a possible implementation manner, determining the target area based on the starting position and the ending position includes:

[0023] Determine a first width from the first character of the text line to the starting position, and use the first width as the horizontal coordinate of the upper left corner of the region;

[0024] Determine a segment height and a top margin of a text segment located above the text line, and sum the segment height and the top margin to obtain a vertical coordinate of an upper left corner of the region;

[0025] Determine a second width between the starting position and the last character of the text line, and use the second width as the area display width;

[0026] Determine the font size corresponding to the characters in the text line, and use the sum of the character height corresponding to the font size and a preset value as the area display height;

[0027] The target area is determined according to the abscissa of the upper left corner of the area, the ordinate of the upper left corner of the area, the display width of the area, and the display height of the area.

[0028] In a possible implementation, obtaining the segment to be read aloud corresponding to the target text includes:

[0029] Obtain the current reading segment corresponding to the target text;

[0030] Determine the next character adjacent to the current reading segment as the starting character, and determine the first line break after the starting character as the ending character;

[0031] The text segment between the start character and the end character is determined as the segment to be read aloud.

[0032] In a possible implementation, the method further includes:

[0033] Determine whether the text segment contains spaces, wherein the spaces include leading spaces and / or trailing spaces;

[0034] In the case that the text segment contains the space, the space is removed from the text segment to obtain the segment to be read aloud.

[0035] In a second aspect, the present application provides a text positioning device, comprising:

[0036] A segment acquisition module, used to acquire the segment to be read aloud corresponding to the target text, and to acquire the current page display content corresponding to the target text, wherein the current page display content is used to represent a part of the target text displayed on the current page of the electronic reader;

[0037] A first determination module is used to determine whether the segment to be read aloud and the content displayed on the current page have an intersection;

[0038] A second determination module is used to determine, for each text line in the current page, whether the segment to be read aloud and the content displayed on the current page intersect, if the segment to be read aloud and the content displayed on the current page intersect;

[0039] A third determination module is used to determine the starting position and the ending position of the intersection of the segment to be read aloud and the text line when there is an intersection between the segment to be read aloud and the text line, and determine the target area based on the starting position and the ending position;

[0040] The area marking module is used to mark the target area when the electronic reader reads the segment to be read aloud, so as to locate the segment to be read aloud.

[0041] In a possible implementation manner, the first determining module is specifically configured to:

[0042] Obtaining a segment first character position index and a segment last character position index corresponding to the segment to be read aloud, wherein the segment first character position index is the position index of the first character in the segment to be read aloud in the target text, and the segment last character position index is the position index of the last character in the segment to be read aloud in the target text;

[0043] Obtain the page first character position index and page last character position index corresponding to the current page display content, wherein the page first character position index is the position index of the first character in the current page display content in the target text, and the page last character position index is the position index of the last character in the current page display content in the target text;

[0044] If the page first character position index is smaller than the segment last character position index, and the page last character position index is larger than the segment first character position index, it is determined that the segment to be read aloud has an intersection with the current page display content.

[0045] In a possible implementation manner, the second determining module is specifically configured to:

[0046] Obtain the first character position index and the last character position index corresponding to the text line, wherein the first character position index is the position index of the first character in the text line in the target text, and the last character position index is the position index of the last character in the text line in the target text;

[0047] If the line end character position index is greater than or equal to the segment first character position index, and the line first character position index is less than or equal to the segment end character position index, it is determined that the segment to be read aloud has an intersection with the text.

[0048] In a possible implementation manner, the third determining module is specifically configured to:

[0049] Determine a maximum value among the first character position index of the row and the first character position index of the segment, and determine the position indicated by the position index corresponding to the maximum value as the starting position;

[0050] A minimum value is determined between the line end character position index and the segment end character position index, and a position indicated by the position index corresponding to the minimum value is determined as the end position.

[0051] In a possible implementation manner, the third determining module is further configured to:

[0052] Determine a first width from the first character of the text line to the starting position, and use the first width as the horizontal coordinate of the upper left corner of the region;

[0053] Determine a segment height and a top margin of a text segment located above the text line, and sum the segment height and the top margin to obtain a vertical coordinate of an upper left corner of the region;

[0054] Determine a second width between the starting position and the last character of the text line, and use the second width as the area display width;

[0055] Determine the font size corresponding to the characters in the text line, and use the sum of the character height corresponding to the font size and a preset value as the area display height;

[0056] The target area is determined according to the abscissa of the upper left corner of the area, the ordinate of the upper left corner of the area, the display width of the area, and the display height of the area.

[0057] In a possible implementation manner, the fragment acquisition module is specifically configured to:

[0058] Obtain the current reading segment corresponding to the target text;

[0059] Determine the next character adjacent to the current reading segment as the starting character, and determine the first line break after the starting character as the ending character;

[0060] The text segment between the start character and the end character is determined as the segment to be read aloud.

[0061] In a possible implementation manner, the fragment acquisition module is further used to:

[0062] Determine whether the text segment contains spaces, wherein the spaces include leading spaces and / or trailing spaces;

[0063] In the case that the text segment contains the space, the space is removed from the text segment to obtain the segment to be read aloud.

[0064] In a third aspect, an electronic device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0065] Memory, used to store computer programs;

[0066] The processor is used to implement any method step described in the first aspect when executing a program stored in the memory.

[0067] In a fourth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any method step described in the first aspect is implemented.

[0068] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned text positioning methods.

[0069] Beneficial effects of the embodiments of the present application:

[0070] The embodiments of the present application provide a text positioning method, device, electronic device and storage medium. In the present application, first, a to-be-read segment corresponding to a target text is obtained, and a current page display content corresponding to the target text is obtained, wherein the current page display content is used to represent a portion of the target text displayed on the current page of an electronic reader. Then, it is determined whether there is an intersection between the to-be-read segment and the current page display content. If there is an intersection between the to-be-read segment and the current page display content, for each text line in the current page, it is determined whether there is an intersection between the to-be-read segment and the text line. If there is an intersection between the to-be-read segment and the text line, the starting position and the ending position of the intersection between the to-be-read segment and the text line are determined, and a target area is determined based on the starting position and the ending position. Finally, in the process of the electronic reader reading the to-be-read segment, the target area is marked to achieve positioning of the to-be-read segment. In this way, the content corresponding to the segment to be read aloud can be located in the text content displayed by the electronic reader, and the area where the located content is located can be marked in real time while the electronic reader is reading the segment to be read aloud, thereby achieving real-time positioning of the content to be read aloud, making it convenient for users to understand the text content corresponding to the current content to be read aloud in real time.

[0071] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0073] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0074] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0075] Figure 1 A flowchart of a text positioning method provided in an embodiment of the present application;

[0076] Figure 2 An example of marking a target area provided in an embodiment of the present application;

[0077] Figure 3 A flowchart of another text positioning method provided in an embodiment of the present application;

[0078] Figure 4 A flowchart of another text positioning method provided in an embodiment of the present application;

[0079] Figure 5 A structural schematic diagram of a text positioning device provided in an embodiment of the present application;

[0080] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0081] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0082] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.

[0083] Figure 1 A flow chart of a text positioning method provided for an embodiment of the present application. The method can be applied to one or more electronic devices such as smart phones, laptops, desktop computers, portable computers, servers, etc. In addition, the execution subject of the method can be hardware or software. When the above-mentioned execution subject is hardware, the execution subject can be one or more of the above-mentioned electronic devices. For example, a single electronic device can execute the method, or multiple electronic devices can cooperate with each other to execute the method. When the above-mentioned execution subject is software, the method can be implemented as multiple software or software modules, or as a single software or software module. No specific limitation is made here.

[0084] like Figure 1 As shown, the method specifically includes:

[0085] S101, obtaining a segment to be read aloud corresponding to a target text, and obtaining current page display content corresponding to the target text, wherein the current page display content is used to represent a portion of the target text displayed on the current page of the electronic reader.

[0086] The segment to be read aloud refers to the text segment in the target text that the electronic reader is about to read aloud.

[0087] The current page display content refers to the page content displayed on the current page of the electronic reader, which is part of the target text. In the application, the target text is pre-paged to obtain at least one page and the layout data corresponding to each page, and the current page display content can be obtained through the corresponding layout data.

[0088] In one embodiment, the text segment specified by the user can be used as the segment to be read aloud. In this way, the segment to be read aloud can be flexibly specified according to user needs.

[0089] In another embodiment, the electronic reader reads the full text of the target text in sequence, and during this process, the next segment to be read can be determined in real time according to the current segment to be read. As for how to determine the next segment to be read in real time according to the current segment to be read, it will be described in detail through the following embodiments, and will not be described in detail here.

[0090] S102: Determine whether the segment to be read aloud has any intersection with the content displayed on the current page.

[0091] In an embodiment of the present application, S102 may specifically include the following steps: obtaining a first character position index and a last character position index corresponding to the segment to be read aloud, wherein the first character position index is the position index of the first character in the segment to be read aloud in the target text, and the last character position index is the position index of the last character in the segment to be read aloud in the target text; obtaining a first character position index and a last character position index corresponding to the content displayed on the current page, wherein the first character position index is the position index of the first character in the content displayed on the current page in the target text, and the last character position index is the position index of the last character in the content displayed on the current page in the target text; if the first character position index is less than the last character position index, and the last character position index is greater than the first character position index, it is determined that the segment to be read aloud has an intersection with the content displayed on the current page.

[0092] From the above description, it can be known that if the page first character position index of the content displayed on the current page is less than the last character position index of the segment to be read (i.e., the segment end character position index), and the last character position index of the content displayed on the current page (i.e., the page end character position index) is greater than the first character position index of the segment to be read (i.e., the segment first character position index), it means that part or all of the content of the segment to be read exists in the content displayed on the current page. Through this solution, it is possible to quickly determine whether the segment to be read has an intersection with the content displayed on the current page based on the page first character position index and page end character position index of the content displayed on the current page, as well as the segment first character position index and segment end character position index of the segment to be read.

[0093] S103: When the segment to be read aloud and the displayed content of the current page have an intersection, for each text line in the current page, determine whether the segment to be read aloud has an intersection with the text line.

[0094] In an embodiment of the present application, S103 may specifically include the following steps: obtaining the first character position index and the end character position index corresponding to the text line, wherein the first character position index is the position index of the first character in the text line in the target text, and the end character position index is the position index of the last character in the text line in the target text; if the end character position index is greater than or equal to the first character position index of the segment, and the first character position index is less than or equal to the end character position index of the segment, it is determined that the segment to be read aloud has an intersection with the text.

[0095] From the above description, it can be seen that in this embodiment, when it is determined that the segment to be read aloud and the content displayed on the current page have an intersection, all text lines in the current page are traversed, and for any text line, if the character position index of its end of the line in the entire target text (i.e., the end of the line character position index) is greater than the character position index of the first character of the text to be read aloud in the entire target text (i.e., the segment first character position index), and the character position index of the beginning of the line in the entire target text (i.e., the line start character position index) is less than or equal to the character position index of the last character of the text to be read aloud in the entire target text (i.e., the segment end character position index), then it means that part or all of the content of the text to be read aloud exists in the content of the text line.

[0096] Through this scheme, it is possible to quickly determine whether the segment to be read aloud has an intersection with any text line in the current page based on the first character position index and the last character position index of each text line in the current page, as well as the first character position index and the last character position index of the segment to be read aloud.

[0097] S104: When the segment to be read aloud and the text line have an intersection, determine a starting position and an ending position of the intersection of the segment to be read aloud and the text line, and determine a target area based on the starting position and the ending position.

[0098] In an embodiment of the present application, determining the starting position and the ending position of the intersection of the segment to be read aloud and the text line may specifically include the following steps: determining the maximum value among the line first character position index and the segment first character position index, and determining the position indicated by the position index corresponding to the maximum value as the starting position; determining the minimum value among the line end character position index and the segment end character position index, and determining the position indicated by the position index corresponding to the minimum value as the ending position.

[0099] In the application, the starting position and the ending position can be calculated by defining the following function:

[0100] Intersection start index: intersectStart = Math.max(line[0], ttsInfo.firstIndex);

[0101] Intersection end index: intersectEnd = Math.min(line[1], ttsInfo.lastIndex);

[0102] The function Math.max means returning the largest number, Math.min means returning the smallest number, line[0] indicates the first character position index of the text line, ttsInfo.firstIndex indicates the first character position index of the fragment, line[1] indicates the last character position index of the text line, and ttsInfo.lastIndex indicates the last character position index of the fragment.

[0103] In this way, according to the above function, the position indicated by the maximum value between the line start character position index and the fragment first character position index can be determined as the starting position, and the position indicated by the minimum value between the line end character position index and the fragment end character position index can be determined as the ending position.

[0104] Then, the area between the starting position and the ending position is determined as the target area.

[0105] S105 . In the process of the electronic reader reading the segment to be read aloud, marking the target area to locate the segment to be read aloud.

[0106] The above-mentioned mark may be a highlight mark, a color mark, a text box mark, etc.

[0107] In the embodiment of the present application, after the target area is determined according to steps S101-S104, it is saved. When the electronic reader finishes reading the current content and starts reading the segment to be read, the target area is marked in real time, thereby locating the segment to be read.

[0108] Figure 2 An example of marking a target area is shown. Figure 2 As shown in FIG. 1 , when the electronic reader reads aloud the content of the segment “Therefore, we need to analyze and study from five aspects…”, the current page on the display screen highlights this content. In this way, it is convenient for users to read.

[0109] In an embodiment of the present application, first, a segment to be read aloud corresponding to a target text is obtained, and the current page display content corresponding to the target text is obtained, wherein the current page display content is used to represent a portion of the target text displayed on the current page of the electronic reader. Then, it is determined whether there is an intersection between the segment to be read aloud and the current page display content. If there is an intersection between the segment to be read aloud and the current page display content, for each text line in the current page, it is determined whether there is an intersection between the segment to be read aloud and the text line. If there is an intersection between the segment to be read aloud and the text line, the starting position and the ending position of the intersection between the segment to be read aloud and the text line are determined, and a target area is determined based on the starting position and the ending position. Finally, in the process of the electronic reader reading aloud the segment to be read aloud, the target area is marked to achieve the positioning of the segment to be read aloud. In this way, the content corresponding to the segment to be read aloud can be located in the text content displayed by the electronic reader, and the area where the located content is located can be marked in real time while the electronic reader is reading the segment to be read aloud, thereby achieving real-time positioning of the content to be read aloud, making it convenient for users to understand the text content corresponding to the current content to be read aloud in real time.

[0110] See also Figure 3 , is a flow chart of another text positioning method provided in an embodiment of the present application. Figure 3 The process shown in the above Figure 1 Based on the process shown in FIG. 1 , how to determine the target area based on the starting position and the ending position is described. Figure 3 As shown, the process may include the following steps:

[0111] S301. Determine a first width from the first character of the text line to the starting position, and use the first width as the horizontal coordinate of the upper left corner of the region.

[0112] From the above description, it can be seen that in this embodiment, starting from the first character of the text line, the widths and character spacing of all characters from the first character to the first character position to be marked (i.e., the starting position) are accumulated to obtain the x-coordinate position of the upper left corner of the area of ​​the text line that needs to be marked.

[0113] S302: Determine a segment height and a top margin of the text segment located above the text line, and sum the segment height and the top margin to obtain the ordinate of the upper left corner of the region.

[0114] The fragment height is the height obtained by adding the line height, line spacing, and paragraph spacing of all text lines above this text line.

[0115] The top margin refers to the distance between the area where text is displayed on the current page and the top of the display screen.

[0116] In the embodiment of the present application, the y coordinate position of the upper left corner is obtained by accumulating the top margin, the line height, line spacing and paragraph spacing of all text lines above the text line.

[0117] In another embodiment, if the current page is the first page of a chapter, that is, the current page contains a title, the y-coordinate position of the upper left corner is obtained by accumulating the top margin, the line height of all text lines above the text line, the line spacing, the paragraph spacing and the title height.

[0118] S303: Determine a second width from the starting position to the last character of the text line, and use the second width as the area display width.

[0119] In an embodiment of the present application, starting from the first character position to be marked (i.e., the starting position), the character width and character spacing of each subsequent character are accumulated until the last character position to be marked or the end of the line, to obtain the initial width, and then the initial width is subtracted from an excess character spacing to obtain the display width of the area between the starting position and the last character of the text line.

[0120] S304: Determine the font size corresponding to the characters in the text line, and use the sum of the character height corresponding to the font size and a preset value as the area display height.

[0121] The preset value can be set by the user according to actual needs.

[0122] As can be seen from the above description, in the embodiment of the present application, the sum of the character height of the characters in the text line and the preset value is used as the area display height. By setting the preset value, it is possible to avoid the mark area failing to cover the bottom edge of English letters such as p and g when displayed.

[0123] S305 , determining the target area according to the abscissa of the upper left corner of the area, the ordinate of the upper left corner of the area, the display width of the area, and the display height of the area.

[0124] From the above description, it can be seen that in the embodiment of the present application, a rectangular target area can be determined based on the horizontal coordinate of the upper left corner of the area, the vertical coordinate of the upper left corner of the area, the area display width and the area display height. The target area contains the same content in the text line as the text to be read aloud.

[0125] pass Figure 3 The process shown can determine the target area according to the starting position and the ending position of the intersection of the segment to be read aloud and the text line, so as to facilitate the subsequent marking display of the content in the text line that is the same as the text to be read aloud.

[0126] See also Figure 4 , is a flow chart of another embodiment of a text positioning method provided in an embodiment of the present application. Figure 4 As shown, the process may include the following steps:

[0127] S401, obtaining the current reading segment corresponding to the target text;

[0128] S402, determining the next character adjacent to the current reading segment as the starting character, and determining the first line break after the starting character as the ending character;

[0129] S403: Determine the text segment between the start character and the end character as the segment to be read aloud.

[0130] For ease of understanding, S401-S403 are described in a unified manner as follows:

[0131] The current reading segment refers to the content of the target text currently read by the electronic reader.

[0132] In actual applications, when the electronic reader is reading the current reading segment, the next sentence of the current reading segment (i.e., the segment to be read) is obtained in advance, and the next sentence is saved, and the target area of ​​the next sentence in the current page is determined. When the electronic reader finishes reading the current reading segment, the electronic reader takes out the saved next sentence as the current reading segment, performs text-to-speech operations (i.e., reading aloud), and marks the target area during the reading process.

[0133] Based on this, in an embodiment of the present application, the next character adjacent to the current reading segment is determined as the starting character, and the first line break after the starting character is determined as the ending character, and the text segment between the starting character and the ending character is determined as the segment to be read aloud.

[0134] In another embodiment, if the length between the start character and the end character of the text segment exceeds a preset length, a text segment of the preset length (such as 100 characters) can be intercepted starting from the start character as the segment to be read aloud. Through this solution, when the next sentence is too long, a part of the content can be intercepted as the segment to be read aloud.

[0135] In the application, there are cases where the start character and the end character are spaces. For this reason, in another embodiment of the present application, the method may further include the following steps:

[0136] Determine whether the text segment contains spaces, where the spaces include leading spaces and / or trailing spaces; in the case where the text segment contains the spaces, remove the spaces from the text segment to obtain the segment to be read aloud.

[0137] For example, after text interception by the start character and the end character, it may contain leading spaces and trailing spaces. For example, "Hello", this text contains two spaces in the front and two spaces in the back. By moving the first character two spaces backward and moving the last character two spaces forward, the position of the character "好" is obtained. In this way, when marking subsequently, only the text part can be marked.

[0138] Through Figure 4 the shown process, during the process of the e-reader reading the current segment to be read aloud, the target area of the next sentence on the current page can be determined in advance. In this way, when the e-reader finishes reading the current segment to be read aloud and starts to read the segment to be read aloud, the target area is marked synchronously. Thus, the synchronization of reading and marking is realized, which is convenient for the user to view.

[0139] In the application, the technical solution provided by the embodiment of the present application can be implemented based on the HarmonyOS Next system. The implementation process of this solution is described below based on the Arkts development language of the HarmonyOS Next system:

[0140] First, define the ReaderTxtPageInfo class to store the page information of each page, which specifically includes the following fields:

[0141] linesContent: string[] = [""]; / / Store the content of each line;

[0142] lineIndexes: number[][] = []; / / Store the start character position index and the end position index of each line;

[0143] wordCount: number = 0; / / Store the number of words on each page;

[0144] firstIndex:number=0; / / Store the index of the first word on each page;

[0145] lastIndex:number=0; / / Store the index of the last word on each page;

[0146] pageNum:number=0; / / Store the current page number.

[0147] In the application, after the target text is paged and laid out in the reader, the content of each page is filled into the object txtPageInfo to store the text data of each page, thereby obtaining at least one page and the layout data corresponding to each page.

[0148] Define the TTSInfo class to store text fragment content, including the following word terminals:

[0149] content: string = "; / / sentence content;

[0150] firstIndex:number=0; / / The index of the first word in the sentence (excluding leading spaces);

[0151] realFirstIndex:number=0; / / The index of the first word of the sentence (including the leading space);

[0152] lastIndex:number=0; / / The index of the last word in the sentence (excluding the trailing space);

[0153] realLastIndex:number=0; / / The index of the last word in the sentence (including the trailing space);

[0154] isLast:boolean=false; / / Is it the last sentence of this chapter?

[0155] Then, based on the above definition, the text positioning process is implemented. The specific process is as follows:

[0156] 1. Extract text fragments from the target text:

[0157] First, define a temporary variable curFirstIndex to store the starting index of the text segment to be retrieved in the target text. The initial value is 0, which is the starting position of the target text.截取从目标文本的curFirstIndex位置到下一个换行符之间的字符串,若该字符串超过预设数量(如100个)字符,则截取curFirstIndex位置到其之后的100个字符,以此作为获取的文本片段content,记录该文本片段的长度为originalLength(即文本片段content的字符数),则该句子的realFirstIndex即为curFirstIndex变量的值,realLastIndex即为realFirstIndex+originalLength-1,realFirstIndex后移前导空格字符数得到firstIndex,realLastIndex向前后缀空格字符数得到lastIndex, 若realLastIndex等于目标文本长度,则当前句为最后一句,isLast为true,否则为false,将数据填充于ttsInfo对象中。

[0158] For example, for the text segment "你好" as content, there are two spaces in front and two spaces at the back. The realFirstIndex of the text segment content is the position of the first character including the spaces, and firstIndex is the position of the character "你" after realFirstIndex is shifted back by two space characters. The realLastIndex is the position of the last character including the spaces, and lastIndex is the position of the character "好" after realLastIndex is shifted forward by two space characters. In this way, only the text part can be marked in subsequent marking.

[0159] I. Text segment positioning:

[0160] 1) If txtPageInfo.firstIndex is less than ttsInfo.lastIndex, and txtPageInfo.lastIndex is greater than or equal to ttsInfo.firstIndex, it means there is an intersection between the text segment and the content of the current page, and there is a text segment that needs to be marked (such as highlighted).

[0161] 2) Traverse the text lines txtPageInfo.lineIndexes of the current page to determine whether the text fragment and the current text line have an intersection. If the current text line end index line[1]>= ttsInfo.firstIndex, and the current text line beginning index line[0]<= ttsInfo.lastIndex, it means that the current line has an intersection with the text fragment.

[0162] 3) Calculate the line drawing area (i.e. the target area):

[0163] First, define the starting index of the intersection between the text segment and the current text line: intersectStart = Math.max(line[0], ttsInfo.firstIndex); define the ending index of the intersection between the text segment and the current text line: intersectEnd = Math.min(line[1], ttsInfo.lastIndex);

[0164] Then, calculate the starting x coordinate of the upper left corner of the target area of ​​this row:

[0165]

[0166]

[0167] That is, starting from the first character of the text line, the width and character spacing of all characters from the first character to the first character position to be marked are accumulated, and the obtained value is the x-coordinate position of the upper left corner of the target area of ​​this line.

[0168] Calculate the starting y coordinate of the upper left corner of the target area of ​​this row:

[0169] let leftY = (txtPageInfo?.pageNum == 0? chapterNameHeight:0) +topMargin + (index * (lineSpacing+fontSize)) +(countNumbersLessThanNum(this.paragraphLines, index) *paragraphSpacing)

[0170] That is, add up the top margin, the line height and line spacing of all lines before the text line to be marked on the current page, and all paragraph spacing. If the current page is the first page, the title height also needs to be added. The resulting value is the y-coordinate position of the starting upper left corner of the highlighted area of ​​this line.

[0171] Calculate the display width of the target area of ​​this row:

[0172]

[0173]

[0174] That is, starting from the first character position to be marked, the subsequent character widths and character spacings are accumulated until the last character position to be marked or the end of the line, and finally an extra character spacing is subtracted to obtain the area display width.

[0175] Calculate the display height of the target area of ​​this line: let height = fontSize + 4, that is, the character height plus 4, where 4 is a preset empirical value and can be set according to actual conditions.

[0176] Finally, perform the drawing operation (taking highlighting as an example):

[0177] this.context.fillStyle = "#3300cd90"

[0178] this.context.fillRect(leftX, leftY, width, height)

[0179] That is, use the color value #3300cd90 to draw a highlight area with a width of width and a height of height starting from the coordinates leftX, leftY of the upper left corner of the starting position of the highlighted text.

[0180] 4) Point to the next line and continue drawing according to the rules in the previous step until all lines of the current page are traversed and drawing is completed.

[0181] This application is implemented based on the Hongmeng Next system. It uses the paging and typesetting algorithm of the mobile reading application to display texts of different sizes on mobile devices of different screen sizes in paging and typesetting. In the text-to-speech reading scenario, the target text is segmented and read aloud. When turning to the page corresponding to the sentence currently being read, the sentence currently being read or the part of the sentence currently being read displayed on the page is highlighted. This realizes the text fragments after the paging and typesetting of the target text of the mobile text reader on the Hongmeng Next system, and quickly locates and highlights the rendering effect in the display area of ​​the screen. It should be noted that this solution is not only applicable to the text-to-speech reading scenario, but also to any scenario where the text fragments need to be located in the reader.

[0182] Based on the same technical concept, the present application embodiment also provides a text positioning device, such as Figure 5 As shown, the device comprises:

[0183] The segment acquisition module 51 is used to acquire the segment to be read aloud corresponding to the target text, and acquire the current page display content corresponding to the target text, wherein the current page display content is used to represent a part of the target text displayed on the current page of the electronic reader;

[0184] A first determination module 52 is used to determine whether the segment to be read aloud and the content displayed on the current page have an intersection;

[0185] A second determination module 53 is used to determine, for each text line in the current page, whether the segment to be read aloud and the content displayed on the current page intersect, if the segment to be read aloud and the content displayed on the current page intersect;

[0186] A third determination module 54 is used to determine the starting position and the ending position of the intersection of the segment to be read aloud and the text line when there is an intersection between the segment to be read aloud and the text line, and determine a target area based on the starting position and the ending position;

[0187] The area marking module 55 is used to mark the target area when the electronic reader reads the segment to be read aloud, so as to locate the segment to be read aloud.

[0188] In a possible implementation manner, the first determining module is specifically configured to:

[0189] Obtaining a segment first character position index and a segment last character position index corresponding to the segment to be read aloud, wherein the segment first character position index is the position index of the first character in the segment to be read aloud in the target text, and the segment last character position index is the position index of the last character in the segment to be read aloud in the target text;

[0190] Obtain the page first character position index and page last character position index corresponding to the current page display content, wherein the page first character position index is the position index of the first character in the current page display content in the target text, and the page last character position index is the position index of the last character in the current page display content in the target text;

[0191] If the page first character position index is smaller than the segment last character position index, and the page last character position index is larger than the segment first character position index, it is determined that the segment to be read aloud has an intersection with the current page display content.

[0192] In a possible implementation manner, the second determining module is specifically configured to:

[0193] Obtain the first character position index and the last character position index corresponding to the text line, wherein the first character position index is the position index of the first character in the text line in the target text, and the last character position index is the position index of the last character in the text line in the target text;

[0194] If the line end character position index is greater than or equal to the segment first character position index, and the line first character position index is less than or equal to the segment end character position index, it is determined that the segment to be read aloud has an intersection with the text.

[0195] In a possible implementation manner, the third determining module is specifically configured to:

[0196] Determine a maximum value among the first character position index of the row and the first character position index of the segment, and determine the position indicated by the position index corresponding to the maximum value as the starting position;

[0197] A minimum value is determined between the line end character position index and the segment end character position index, and a position indicated by the position index corresponding to the minimum value is determined as the end position.

[0198] In a possible implementation manner, the third determining module is further configured to:

[0199] Determine a first width from the first character of the text line to the starting position, and use the first width as the horizontal coordinate of the upper left corner of the region;

[0200] Determine a segment height and a top margin of a text segment located above the text line, and sum the segment height and the top margin to obtain a vertical coordinate of an upper left corner of the region;

[0201] Determine a second width between the starting position and the last character of the text line, and use the second width as the area display width;

[0202] Determine the font size corresponding to the characters in the text line, and use the sum of the character height corresponding to the font size and a preset value as the area display height;

[0203] The target area is determined according to the abscissa of the upper left corner of the area, the ordinate of the upper left corner of the area, the display width of the area, and the display height of the area.

[0204] In a possible implementation manner, the fragment acquisition module is specifically configured to:

[0205] Obtain the current reading segment corresponding to the target text;

[0206] Determine the next character adjacent to the current reading segment as the starting character, and determine the first line break after the starting character as the ending character;

[0207] The text segment between the start character and the end character is determined as the segment to be read aloud.

[0208] In a possible implementation manner, the fragment acquisition module is further used to:

[0209] Determine whether the text segment contains spaces, wherein the spaces include leading spaces and / or trailing spaces;

[0210] In the case that the text segment contains the space, the space is removed from the text segment to obtain the segment to be read aloud.

[0211] Based on the same technical concept, the embodiment of the present application also provides an electronic device, such as Figure 6 As shown, it includes a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.

[0212] Memory 113, used for storing computer programs;

[0213] The processor 111 is used to execute the program stored in the memory 113 to implement the following steps:

[0214] Obtaining a segment to be read aloud corresponding to the target text, and obtaining the current page display content corresponding to the target text, wherein the current page display content is used to represent a portion of the target text displayed on the current page of the electronic reader;

[0215] Determine whether the segment to be read aloud and the content displayed on the current page have an intersection;

[0216] In the case that the segment to be read aloud and the displayed content of the current page have an intersection, for each text line in the current page, determining whether the segment to be read aloud and the text line have an intersection;

[0217] In the case where the segment to be read aloud and the text line have an intersection, determining a starting position and an ending position of the intersection of the segment to be read aloud and the text line, and determining a target area based on the starting position and the ending position;

[0218] In the process of the electronic reader reading aloud the segment to be read aloud, the target area is marked to achieve the positioning of the segment to be read aloud.

[0219] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0220] The communication interface is used for communication between the above electronic device and other devices.

[0221] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0222] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0223] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned text positioning methods are implemented.

[0224] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the text positioning methods in the above embodiments.

[0225] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0226] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0227] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.

[0228] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A text positioning method, characterized in that: The method comprises: Obtaining a segment to be read aloud corresponding to the target text, and obtaining the current page display content corresponding to the target text, wherein the current page display content is used to represent a portion of the target text displayed on the current page of the electronic reader; Determine whether the segment to be read aloud and the content displayed on the current page have an intersection; In the case that the segment to be read aloud and the displayed content of the current page have an intersection, for each text line in the current page, determining whether the segment to be read aloud and the text line have an intersection; In the case where the segment to be read aloud and the text line have an intersection, determining a starting position and an ending position of the intersection of the segment to be read aloud and the text line, and determining a target area based on the starting position and the ending position; In the process of the electronic reader reading aloud the segment to be read aloud, the target area is marked to achieve the positioning of the segment to be read aloud.

2. The method according to claim 1, characterized in that The determining whether the segment to be read aloud has an intersection with the content displayed on the current page includes: Obtaining a segment first character position index and a segment last character position index corresponding to the segment to be read aloud, wherein the segment first character position index is the position index of the first character in the segment to be read aloud in the target text, and the segment last character position index is the position index of the last character in the segment to be read aloud in the target text; Obtain the page first character position index and page last character position index corresponding to the current page display content, wherein the page first character position index is the position index of the first character in the current page display content in the target text, and the page last character position index is the position index of the last character in the current page display content in the target text; If the page first character position index is smaller than the segment last character position index, and the page last character position index is larger than the segment first character position index, it is determined that the segment to be read aloud has an intersection with the current page display content.

3. The method according to claim 2, characterized in that The determining whether the segment to be read aloud and the text line have an intersection includes: Obtain the first character position index and the last character position index corresponding to the text line, wherein the first character position index is the position index of the first character in the text line in the target text, and the last character position index is the position index of the last character in the text line in the target text; If the line end character position index is greater than or equal to the segment first character position index, and the line first character position index is less than or equal to the segment end character position index, it is determined that the segment to be read aloud has an intersection with the text.

4. The method according to claim 3, characterized in that The step of determining the starting position and the ending position of the intersection of the segment to be read aloud and the text line includes: Determine a maximum value among the first character position index of the row and the first character position index of the segment, and determine the position indicated by the position index corresponding to the maximum value as the starting position; A minimum value is determined between the line end character position index and the segment end character position index, and a position indicated by the position index corresponding to the minimum value is determined as the end position.

5. The method according to claim 1, characterized in that The determining of the target area based on the starting position and the ending position comprises: Determine a first width from the first character of the text line to the starting position, and use the first width as the horizontal coordinate of the upper left corner of the region; Determine a segment height and a top margin of the text segment located above the text line, and sum the segment height and the top margin to obtain the ordinate of the upper left corner of the region; Determine a second width between the starting position and the last character of the text line, and use the second width as the area display width; Determine the font size corresponding to the characters in the text line, and use the sum of the character height corresponding to the font size and a preset value as the area display height; The target area is determined according to the abscissa of the upper left corner of the area, the ordinate of the upper left corner of the area, the display width of the area, and the display height of the area.

6. The method according to claim 1, characterized in that The step of obtaining the segment to be read aloud corresponding to the target text includes: Obtain the current reading segment corresponding to the target text; Determine the next character adjacent to the current reading segment as the starting character, and determine the first line break after the starting character as the ending character; The text segment between the start character and the end character is determined as the segment to be read aloud.

7. The method according to claim 6, characterized in that The method further comprises: Determine whether the text segment contains spaces, wherein the spaces include leading spaces and / or trailing spaces; In the case that the text segment contains the space, the space is removed from the text segment to obtain the segment to be read aloud.

8. A text positioning device, characterized in that: The device comprises: A segment acquisition module, used to acquire the segment to be read aloud corresponding to the target text, and to acquire the current page display content corresponding to the target text, wherein the current page display content is used to represent a part of the target text displayed on the current page of the electronic reader; A first determination module is used to determine whether the segment to be read aloud and the content displayed on the current page have an intersection; A second determination module is used to determine, for each text line in the current page, whether the segment to be read aloud and the content displayed on the current page intersect, if the segment to be read aloud and the content displayed on the current page intersect; A third determination module is used to determine the starting position and the ending position of the intersection of the segment to be read aloud and the text line when there is an intersection between the segment to be read aloud and the text line, and determine the target area based on the starting position and the ending position; The area marking module is used to mark the target area when the electronic reader reads the segment to be read aloud, so as to locate the segment to be read aloud.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; The processor is used to implement the text positioning method described in any one of claims 1 to 7 when executing the program stored in the memory.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the text positioning method according to any one of claims 1 to 7 is implemented.