Name:           speech-dispatcher
Version:        0.11.5
Release:        1
Summary:        Common high-level interface to speech synthesis
License:        GPL-2.0-or-later and LGPL-2.1-only or LGPL-2.0-only
URL:            http://devel.freebsoft.org/speechd
Source0:        https://github.com/brailcom/speechd/releases/download/%{version}/speech-dispatcher-%{version}.tar.gz
Source1:        http://www.freebsoft.org/pub/projects/sound-icons/sound-icons-0.1.tar.gz

Patch0001:      0001-Remove-pyxdg-dependency.patch
 
BuildRequires:  alsa-lib-devel desktop-file-utils dotconf-devel espeak-ng-devel flite-devel
BuildRequires:  glib2-devel intltool libao-devel libtool-ltdl-devel libsndfile-devel
BuildRequires:  pulseaudio-libs-devel python3-devel python3-setuptools texinfo systemd gcc gcc-c++ make
Provides:       speech-dispatcher-utils = %{version}-%{release}
Obsoletes:      speech-dispatcher-utils < %{version}-%{release}
Requires:       python3-speechd = %{version}-%{release} speech-dispatcher-espeak-ng
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd

%description
Speech Dispatcher project provides a high-level device independent layer for
access to speech synthesis through a simple, stable and well documented interface.

%package        devel
Summary:        Development files for speech-dispatcher
License:        GPLv2+
Requires:       speech-dispatcher = %{version}-%{release}

%description    devel
The package contains libraries and header files for developing applications that
use speech-dispatcher.

%package        help
Summary:        Documentation for speech-dispatcher
License:        GPLv2+
Requires:       speech-dispatcher = %{version}-%{release}
Requires(post): info
Requires(preun):info
Provides:       speech-dispatcher-doc = %{version}-%{release}
Obsoletes:      speech-dispatcher-doc < %{version}-%{release}
BuildArch:      noarch

%description    help
Documentation for speech-dispatcher

%package        espeak-ng
Summary:        Speech Dispatcher espeak-ng module
Requires:       speech-dispatcher = %{version}-%{release}
Obsoletes:      speech-dispatcher-espeak < 0.8.8-5

%description    espeak-ng
This package contains the espeak-ng output module for Speech Dispatcher.

%package        festival
Summary:        Speech Dispatcher festival module
Requires:       speech-dispatcher = %{version}-%{release} festival-freebsoft-utils
Obsoletes:      speech-dispatcher < 0.8.1-2

%description    festival
This package contains the festival output module for Speech Dispatcher.

%package        flite
Summary:        Speech Dispatcher flite module
Requires:       speech-dispatcher = %{version}-%{release}
Obsoletes:      speech-dispatcher < 0.8.1-2

%description    flite
This package contains the flite output module for Speech Dispatcher.

%package -n     python3-speechd
Summary:        Python v3 Client API for speech-dispatcher
License:        GPLv2+
Requires:       speech-dispatcher = %{version}-%{release}

%description -n python3-speechd
Python v3 module for speech-dispatcher

%prep
%autosetup -n speech-dispatcher-%{version} -p1
tar xf %{SOURCE1}

%build
%configure --with-alsa --with-pulse --with-libao --without-oss --without-nas --with-flite --without-espeak \
	--with-espeak-ng --sysconfdir=%{_sysconfdir} --with-default-audio-method=pulse \
	--with-kali=no --with-baratinoo=no --with-voxin=no --with-ibmtts=no --disable-static \
	--with-module-bindir=%{_libdir}/speech-dispatcher-modules/

%make_build V=1

%install
%make_install
install -d %{buildroot}%{_unitdir}
install -p -m 0644 sound-icons-0.1/* %{buildroot}%{_datadir}/sounds/speech-dispatcher/
%find_lang speech-dispatcher
%delete_la_and_a
install -d %{buildroot}%{_sysconfdir}/speech-dispatcher/clients
install -d %{buildroot}%{_sysconfdir}/speech-dispatcher/modules
mv %{buildroot}%{_datadir}/speech-dispatcher/conf/speechd.conf %{buildroot}%{_sysconfdir}/speech-dispatcher/
mv %{buildroot}%{_datadir}/speech-dispatcher/conf/clients/* %{buildroot}%{_sysconfdir}/speech-dispatcher/clients
mv %{buildroot}%{_datadir}/speech-dispatcher/conf/modules/* %{buildroot}%{_sysconfdir}/speech-dispatcher/modules
install -d -m 0700 %{buildroot}%{_localstatedir}/log/speech-dispatcher/
desktop-file-validate %{buildroot}/%{_datadir}/speech-dispatcher/conf/desktop/speechd.desktop
sed 's/# AudioOutputMethod "pulse,alsa"/AudioOutputMethod "pulse,alsa"/' %{buildroot}%{_sysconfdir}/speech-dispatcher/speechd.conf
%pre espeak-ng
espeak_ng_conf=%{_sysconfdir}/speech-dispatcher/modules/espeak-ng.conf
if [ 0$1 -eq 1 -a ! -f $espeak_ng_conf ]; then
    espeak_conf=%{_sysconfdir}/speech-dispatcher/modules/espeak.conf
    if [ -f $espeak_conf ]; then
        cp $espeak_conf $espeak_ng_conf || :
    fi
    speechd_conf=%{_sysconfdir}/speech-dispatcher/speechd.conf
    if [ -f $speechd_conf ]; then
        sed -i.bak-espeak -r \
          -e 's/^(\s*AddModule\s+)("?)espeak\2\s+("?)sd_espeak\3\s+("?)espeak.conf\4(\s*(#.*)?)$/\1"espeak-ng" "sd_espeak-ng" "espeak-ng.conf"\5/' \
          -e 's/^(\s*AddModule\s+("?)[^"]*\2\s+)("?)sd_espeak\3(\s+("?)[^"]*\5(\s*(#.*)?))$/\1"sd_espeak-ng"\4/' \
          -e 's/^(\s*DefaultModule\s+)("?)espeak\2(\s*(#.*)?)$/\1espeak-ng\3/' \
          -e 's/^(\s*LanguageDefaultModule\s+("?)[^"]*\2\s+)("?)espeak\3(\s*(#.*)?)$/\1"espeak-ng"\4/' \
          $speechd_conf || :
    fi
fi
%post
/sbin/ldconfig
%systemd_post speech-dispatcherd.service
%postun
/sbin/ldconfig
%systemd_postun_with_restart speech-dispatcherd.service
%preun
%systemd_preun speech-dispatcherd.service
%post help
/sbin/install-info %{_infodir}/speech-dispatcher.info %{_infodir}/dir || :
/sbin/install-info %{_infodir}/spd-say.info %{_infodir}/dir || :
/sbin/install-info %{_infodir}/ssip.info %{_infodir}/dir || :
%preun help
if [ $1 = 0 ]; then
    /sbin/install-info --delete %{_infodir}/speech-dispatcher.info %{_infodir}/dir || :
    /sbin/install-info --delete %{_infodir}/spd-say.info %{_infodir}/dir || :
    /sbin/install-info --delete %{_infodir}/ssip.info %{_infodir}/dir || :
fi

%files -f speech-dispatcher.lang
%license COPYING.LGPL
%doc NEWS README.md
%dir %{_sysconfdir}/speech-dispatcher/{clients,modules}
%config(noreplace) %{_sysconfdir}/speech-dispatcher/speechd.conf
%config(noreplace) %{_sysconfdir}/speech-dispatcher/clients/*.conf
%config(noreplace) %{_sysconfdir}/speech-dispatcher/modules/*.conf
%exclude %{_sysconfdir}/speech-dispatcher/modules/{espeak*.conf,festival.conf,flite.conf}
%{_bindir}/speech-dispatcher
%{_datadir}/speech-dispatcher/
%{_libdir}/{libspeechd.so.2,libspeechd.so.2.6.0}
%{_libdir}/speech-dispatcher-modules/{sd_cicero,sd_dummy,sd_generic}
%{_libdir}/speech-dispatcher/spd*.so
%{_datadir}/sounds/speech-dispatcher
%dir %attr(0700, root, root) %{_localstatedir}/log/speech-dispatcher/
%{_unitdir}/speech-dispatcherd.service
%{_bindir}/{spd-conf,spd-say,spdsend}

%files devel
%{_includedir}/*
%{_libdir}/lib*.so
%{_libdir}/pkgconfig/*.pc

%files help
%{_infodir}/*
%exclude %{_infodir}/dir

%files espeak-ng
%config(noreplace) %{_sysconfdir}/speech-dispatcher/modules/espeak-ng.conf
%{_libdir}/speech-dispatcher-modules/sd_espeak-ng
%{_libdir}/speech-dispatcher-modules/sd_espeak-ng-mbrola

%files festival
%config(noreplace) %{_sysconfdir}/speech-dispatcher/modules/festival.conf
%{_libdir}/speech-dispatcher-modules/sd_festival

%files flite
%config(noreplace) %{_sysconfdir}/speech-dispatcher/modules/flite.conf
%{_libdir}/speech-dispatcher-modules/sd_flite

%files -n python3-speechd
%{python3_sitearch}/speechd*

%changelog
* Thu Sep 28 2023 wulei <wu_lei@hoperun.com> - 0.11.5-1
- Update to 0.11.5

* Tue Jul 25 2023 chenchen <chen_aka_jan@163.com> - 0.11.4-1
- Upgrade to version 0.11.4

* Mon May 23 2022 wulei <wulei80@h-partners.com> - 0.11.1-1
- Update package

* Sat Jul 31 2021 chenyanpanHW <chenyanpan@huawei.com> - 0.8.8-12
- DESC: delete -S git from %autosetup, and delete BuildRequires git

* Fri Jul 30 2021 yaokai <yaokai13@huawei.com> - 0.8.8-11
- Fix global variable gcc10

* Mon May 31 2021 huanghaitao <huanghaitao8@huawei.com> - 0.8.8-10
- Completing build dependencies to fix gcc compiler missing error

* Sat Nov 30 2019 Ling Yang <lingyang2@huawei.com> - 0.8.8-9
- Package init
