mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #1183 from omnivore-app/fix/remove-emoji-from-speech-file
This commit is contained in:
commit
047dd4735f
2 changed files with 26 additions and 2 deletions
|
|
@ -117,7 +117,7 @@ function emit(textItems: string[], text: string) {
|
|||
}
|
||||
|
||||
function cleanTextNode(textNode: ChildNode): string {
|
||||
return _.escape(textNode.textContent ?? ''.replace(/\s+/g, ' '))
|
||||
return stripEmojis(_.escape(textNode.textContent ?? ''.replace(/\s+/g, ' ')))
|
||||
}
|
||||
|
||||
function emitTextNode(
|
||||
|
|
@ -252,6 +252,12 @@ export const htmlToSsmlItems = (
|
|||
return items
|
||||
}
|
||||
|
||||
export const stripEmojis = (text: string): string => {
|
||||
const emojiRegex =
|
||||
/(?![*#0-9]+)[\p{Emoji}\p{Emoji_Modifier}\p{Emoji_Component}\p{Emoji_Modifier_Base}\p{Emoji_Presentation}]/gu
|
||||
return text.replace(emojiRegex, '').replace(/\s+/g, ' ')
|
||||
}
|
||||
|
||||
const textToUtterance = ({
|
||||
tokenizer,
|
||||
idx,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,24 @@
|
|||
import 'mocha'
|
||||
import { expect } from 'chai'
|
||||
import { htmlToSsmlItems } from '../src/htmlToSsml'
|
||||
import { htmlToSsmlItems, stripEmojis } from '../src/htmlToSsml'
|
||||
|
||||
describe('stripEmojis', () => {
|
||||
it('strips emojis from text and removes the extra space', () => {
|
||||
const text = '🥛The Big Short guy is back with a new prediction'
|
||||
|
||||
expect(stripEmojis(text)).to.equal(
|
||||
'The Big Short guy is back with a new prediction'
|
||||
)
|
||||
})
|
||||
|
||||
it('strips emojis from html and removes the extra space', () => {
|
||||
const text = `<h2 data-omnivore-anchor-idx="37">🧠Brain food</h2>`
|
||||
|
||||
expect(stripEmojis(text)).to.equal(
|
||||
`<h2 data-omnivore-anchor-idx="37">Brain food</h2>`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('htmlToSsmlItems', () => {
|
||||
const TEST_OPTIONS = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue