Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
7ea5c465
Commit
7ea5c465
authored
Jul 29, 2015
by
Felix Paul Kühne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
text renderer: add basic text to speech synthesis for OS X (#11893)
parent
d962b826
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
167 additions
and
0 deletions
+167
-0
modules/text_renderer/Makefile.am
modules/text_renderer/Makefile.am
+6
-0
modules/text_renderer/nsspeechsynthesizer.m
modules/text_renderer/nsspeechsynthesizer.m
+160
-0
po/POTFILES.in
po/POTFILES.in
+1
-0
No files found.
modules/text_renderer/Makefile.am
View file @
7ea5c465
...
...
@@ -36,6 +36,12 @@ libquartztext_plugin_la_LDFLAGS = $(AM_LDLFAGS) -rpath '$(textdir)' \
EXTRA_LTLIBRARIES
+=
libquartztext_plugin.la
text_LTLIBRARIES
+=
$(LTLIBquartztext)
if
HAVE_OSX
libnsspeechsynthesizer_plugin_la_SOURCES
=
text_renderer/nsspeechsynthesizer.m
libnsspeechsynthesizer_plugin_la_LDFLAGS
=
-Wl
,-framework,Cocoa
text_LTLIBRARIES
+=
libnsspeechsynthesizer_plugin.la
endif
libsvg_plugin_la_SOURCES
=
text_renderer/svg.c
libsvg_plugin_la_CPPFLAGS
=
$(AM_CPPFLAGS)
$(SVG_CFLAGS)
libsvg_plugin_la_LDFLAGS
=
$(AM_LDFLAGS)
-rpath
'
$(textdir)
'
...
...
modules/text_renderer/nsspeechsynthesizer.m
0 → 100644
View file @
7ea5c465
/*****************************************************************************
* nsspeechsynthesizer.m: Simple text to Speech renderer for Mac OS X
*****************************************************************************
* Copyright (C) 2015 VLC authors and VideoLAN
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan # org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_filter.h>
#import <Cocoa/Cocoa.h>
static
int
Create
(
vlc_object_t
*
);
static
void
Destroy
(
vlc_object_t
*
);
static
int
RenderText
(
filter_t
*
,
subpicture_region_t
*
,
subpicture_region_t
*
,
const
vlc_fourcc_t
*
);
vlc_module_begin
()
set_description
(
N_
(
"Speech synthesis for Mac OS X"
))
set_category
(
CAT_VIDEO
)
set_subcategory
(
SUBCAT_VIDEO_SUBPIC
)
set_capability
(
"text renderer"
,
50
)
set_callbacks
(
Create
,
Destroy
)
vlc_module_end
()
struct
filter_sys_t
{
NSSpeechSynthesizer
*
speechSynthesizer
;
NSString
*
currentLocale
;
NSString
*
lastString
;
};
static
int
Create
(
vlc_object_t
*
p_this
)
{
filter_t
*
p_filter
=
(
filter_t
*
)
p_this
;
filter_sys_t
*
p_sys
;
p_filter
->
p_sys
=
p_sys
=
malloc
(
sizeof
(
filter_sys_t
));
if
(
!
p_sys
)
return
VLC_ENOMEM
;
p_sys
->
currentLocale
=
p_sys
->
lastString
=
@""
;
p_sys
->
speechSynthesizer
=
[[
NSSpeechSynthesizer
alloc
]
init
];
p_filter
->
pf_render
=
RenderText
;
return
VLC_SUCCESS
;
}
static
void
Destroy
(
vlc_object_t
*
p_this
)
{
filter_t
*
p_filter
=
(
filter_t
*
)
p_this
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
[
p_sys
->
speechSynthesizer
stopSpeaking
];
[
p_sys
->
speechSynthesizer
release
];
p_sys
->
speechSynthesizer
=
nil
;
[
p_sys
->
lastString
release
];
p_sys
->
lastString
=
nil
;
[
p_sys
->
currentLocale
release
];
p_sys
->
currentLocale
=
nil
;
free
(
p_sys
);
}
static
NSString
*
languageCodeForString
(
NSString
*
string
)
{
return
(
NSString
*
)
CFStringTokenizerCopyBestStringLanguage
((
CFStringRef
)
string
,
CFRangeMake
(
0
,
[
string
length
]));
}
static
int
RenderText
(
filter_t
*
p_filter
,
subpicture_region_t
*
p_region_out
,
subpicture_region_t
*
p_region_in
,
const
vlc_fourcc_t
*
p_chroma_list
)
{
@autoreleasepool
{
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
text_segment_t
*
p_segment
=
p_region_in
->
p_text
;
if
(
!
p_segment
)
return
VLC_EGENERIC
;
for
(
const
text_segment_t
*
s
=
p_segment
;
s
!=
NULL
;
s
=
s
->
p_next
)
{
if
(
!
s
->
psz_text
)
continue
;
if
(
strlen
(
s
->
psz_text
)
==
0
)
continue
;
NSString
*
stringToSpeech
=
[
NSString
stringWithUTF8String
:
s
->
psz_text
];
if
([
p_sys
->
lastString
isEqualToString
:
stringToSpeech
])
continue
;
if
([
stringToSpeech
isEqualToString
:
@"
\n
"
])
continue
;
p_sys
->
lastString
=
[
stringToSpeech
retain
];
msg_Dbg
(
p_filter
,
"Speaking '%s'"
,
[
stringToSpeech
UTF8String
]);
NSString
*
detectedLocale
=
languageCodeForString
(
stringToSpeech
);
if
(
detectedLocale
!=
nil
)
{
if
(
!
[
detectedLocale
isEqualToString
:
p_sys
->
currentLocale
])
{
p_sys
->
currentLocale
=
[
detectedLocale
retain
];
msg_Dbg
(
p_filter
,
"switching speaker locale to '%s'"
,
[
p_sys
->
currentLocale
UTF8String
]);
NSArray
*
voices
=
[
NSSpeechSynthesizer
availableVoices
];
NSUInteger
count
=
voices
.
count
;
NSRange
range
=
NSMakeRange
(
0
,
2
);
for
(
NSUInteger
i
=
0
;
i
<
count
;
i
++
)
{
NSDictionary
*
voiceAttributes
=
[
NSSpeechSynthesizer
attributesForVoice
:
voices
[
i
]];
NSString
*
voiceLanguage
=
voiceAttributes
[
@"VoiceLanguage"
];
if
([
p_sys
->
currentLocale
isEqualToString
:[
voiceLanguage
substringWithRange
:
range
]])
{
NSString
*
voiceName
=
voiceAttributes
[
@"VoiceName"
];
msg_Dbg
(
p_filter
,
"switched to voice '%s'"
,
[
voiceName
UTF8String
]);
if
([
voiceName
isEqualToString
:
@"Agnes"
]
||
[
voiceName
isEqualToString
:
@"Albert"
])
continue
;
[
p_sys
->
speechSynthesizer
setVoice
:
voices
[
i
]];
break
;
}
}
}
}
[
p_sys
->
speechSynthesizer
startSpeakingString
:
stringToSpeech
];
}
return
VLC_SUCCESS
;
}
}
po/POTFILES.in
View file @
7ea5c465
...
...
@@ -1059,6 +1059,7 @@ modules/stream_out/stats.c
modules/stream_out/standard.c
modules/stream_out/transcode/transcode.c
modules/text_renderer/freetype.c
modules/text_renderer/nsspeechsynthesizer.m
modules/text_renderer/quartztext.c
modules/text_renderer/svg.c
modules/text_renderer/tdummy.c
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment