├── lib
└── libmsc.so
├── src
├── msp_errors.h
├── speech_recognizer.c
├── speech_recognizer.h
├── formats.h
├── pinyin_widget.h
├── chinese2pinyin.h
├── listen_voice.h
├── pinyin_widget.cpp
├── waveform.h
├── main_window.h
├── utils.h
├── main.cpp
├── linuxrec.h
├── listen_voice.cpp
├── chinese2pinyin.cpp
├── main_window.cpp
├── utils.cpp
├── msp_types.h
├── waveform.cpp
├── qtts.h
├── qise.h
├── qisr.h
├── msp_cmn.h
└── linuxrec.c
├── .gitignore
├── deepin-pinyin-assistant.qrc
├── deepin-pinyin-assistant.desktop
├── README.md
├── deepin-pinyin-assistant.pro
├── COPYING
└── LICENSE
/lib/libmsc.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/manateelazycat/deepin-pinyin-assistant/HEAD/lib/libmsc.so
--------------------------------------------------------------------------------
/src/msp_errors.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/manateelazycat/deepin-pinyin-assistant/HEAD/src/msp_errors.h
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Makefile
2 | moc_*.o
3 | moc_*.cpp
4 | build/
5 | *.qm
6 | !nethogs/Makefile
7 | *.user
8 | *.user.*
9 |
--------------------------------------------------------------------------------
/src/speech_recognizer.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/manateelazycat/deepin-pinyin-assistant/HEAD/src/speech_recognizer.c
--------------------------------------------------------------------------------
/src/speech_recognizer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/manateelazycat/deepin-pinyin-assistant/HEAD/src/speech_recognizer.h
--------------------------------------------------------------------------------
/deepin-pinyin-assistant.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | dict/pinyin.dict
4 |
5 |
6 |
--------------------------------------------------------------------------------
/deepin-pinyin-assistant.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Categories=System;Qt;
3 | Comment=Pinyin Assistant
4 | Exec=deepin-pinyin-assistant
5 | GenericName=Pinyin Assistant
6 | Icon=deepin-pinyin-assistant
7 | Name=Deepin Pinyin Assistant
8 | Type=Application
9 |
10 |
11 | # Translations
12 | Name[zh_CN]=深度拼音助手
13 | Icon[zh_CN]=deepin-pinyin-assistant
14 | Comment[zh_CN]=语音转拼音
15 | GenericName[zh_CN]=语音转拼音
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 深度拼音助手
2 |
3 | 深度拼音助手是一款帮助小朋友学习拼音的工具,启动助手以后说出想拼写的单词,会自动用讯飞API转换语音成为对应的汉字和拼音。
4 | 小朋友根据语音识别出的汉字拼音进行拼音输入法学习打字。
5 |
6 | ## 依赖
7 |
8 | 拷贝讯飞的动态库到系统目录:
9 |
10 | * sudo cp ./lib/libmsc.so /usr/lib/x86_64-linux-gnu/
11 |
12 | ## 安装方法
13 |
14 | * mkdir build
15 | * cd build
16 | * qmake ..
17 | * make
18 |
19 | ## 使用
20 |
21 | * ./deepin-pinyin-assistant
22 |
23 | 建议把这个命令绑定到快捷键,方便快速唤醒拼音助手。
24 |
25 | ## License
26 |
27 | 深度拼音助手以GPLv3协议发布,禁止违反GPLv3协议非法闭源.
28 |
--------------------------------------------------------------------------------
/src/formats.h:
--------------------------------------------------------------------------------
1 | #ifndef FORMATS_H_160601_TT
2 | #define FORMATS_H_160601_TT 1
3 |
4 | #ifndef WAVE_FORMAT_PCM
5 | #define WAVE_FORMAT_PCM 1
6 | typedef struct tWAVEFORMATEX {
7 | unsigned short wFormatTag;
8 | unsigned short nChannels;
9 | unsigned int nSamplesPerSec;
10 | unsigned int nAvgBytesPerSec;
11 | unsigned short nBlockAlign;
12 | unsigned short wBitsPerSample;
13 | unsigned short cbSize;
14 | } WAVEFORMATEX;
15 | #endif
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/src/pinyin_widget.h:
--------------------------------------------------------------------------------
1 | #ifndef PINYINWIDGET_H
2 | #define PINYINWIDGET_H
3 |
4 | #include
5 |
6 | class PinyinWidget : public QWidget
7 | {
8 | Q_OBJECT
9 |
10 | public:
11 | PinyinWidget(QWidget *parent = 0);
12 |
13 | void setPinyin(QStringList chineseWords, QStringList pinyinWords);
14 |
15 | protected:
16 | void paintEvent(QPaintEvent *event);
17 |
18 | private:
19 | QStringList chineseWords;
20 | QStringList pinyinWords;
21 | };
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/src/chinese2pinyin.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015 LiuLang. All rights reserved.
2 | // Use of this source is governed by General Public License that can be found
3 | // in the LICENSE file.
4 |
5 | #ifndef SERVICE_BACKEND_CHINESE2PINYIN_H_
6 | #define SERVICE_BACKEND_CHINESE2PINYIN_H_
7 |
8 | #include
9 |
10 | namespace Pinyin {
11 | QString Chinese2Pinyin(const QString& words);
12 | QStringList splitChineseToPinyin(QString &pinyin);
13 | QStringList splitChinese(QString &pinyin);
14 | }
15 |
16 | #endif // SERVICE_BACKEND_CHINESE2PINYIN_H_
17 |
--------------------------------------------------------------------------------
/src/listen_voice.h:
--------------------------------------------------------------------------------
1 | #ifndef LISTENVOICE_H
2 | #define LISTENVOICE_H
3 |
4 | #include
5 | #include
6 |
7 | class ListenVoice : public QThread
8 | {
9 | Q_OBJECT
10 |
11 | public:
12 | ListenVoice(QObject *parent = 0);
13 |
14 | void startListen();
15 |
16 | static void listenFromMicrophone(const char* sessionBeginParams);
17 | static void showResult(char *string, char isOver);
18 | static void resultHandler(const char *result, char isLast);
19 | static void speechBeginHandler();
20 | static void speechEndHandler(int reason);
21 |
22 | signals:
23 | void voiceText(QString text);
24 |
25 | protected:
26 | void run();
27 | };
28 |
29 | #endif
30 |
31 |
--------------------------------------------------------------------------------
/src/pinyin_widget.cpp:
--------------------------------------------------------------------------------
1 | #include "pinyin_widget.h"
2 | #include "utils.h"
3 | #include
4 | #include
5 |
6 | PinyinWidget::PinyinWidget(QWidget *parent) : QWidget(parent)
7 | {
8 |
9 | }
10 |
11 | void PinyinWidget::setPinyin(QStringList cWords, QStringList pWords)
12 | {
13 | chineseWords = cWords;
14 | pinyinWords = pWords;
15 |
16 | repaint();
17 | }
18 |
19 | void PinyinWidget::paintEvent(QPaintEvent *)
20 | {
21 | QPainter painter(this);
22 | painter.setRenderHint(QPainter::Antialiasing, true);
23 |
24 |
25 | int x = 0;
26 | int wordWidth = 60;
27 |
28 | int pinyinRenderY = 0;
29 | int chineseRenderY = 30;
30 |
31 | int paddingX = 20;
32 |
33 | for (int i = 0; i < chineseWords.length(); i++) {
34 | Utils::setFontSize(painter, 12);
35 | painter.setPen(QPen(QColor("#2CA7F8")));
36 | painter.drawText(QRect(paddingX + x, pinyinRenderY, rect().width() - x, rect().height()), Qt::AlignLeft | Qt::AlignTop, pinyinWords[i].toUpper());
37 |
38 | Utils::setFontSize(painter, 16);
39 | painter.setPen(QPen(QColor("#333333")));
40 | painter.drawText(QRect(paddingX + x, chineseRenderY, rect().width() - x, rect().height()), Qt::AlignLeft | Qt::AlignTop, chineseWords[i]);
41 |
42 | x += wordWidth;
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/src/waveform.h:
--------------------------------------------------------------------------------
1 | /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
2 | * -*- coding: utf-8 -*-
3 | *
4 | * Copyright (C) 2011 ~ 2017 Deepin, Inc.
5 | * 2011 ~ 2017 Wang Yong
6 | *
7 | * Author: Wang Yong
8 | * Maintainer: Wang Yong
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program. If not, see .
22 | */
23 |
24 | #ifndef WAVEFORM_H
25 | #define WAVEFORM_H
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 | class Waveform : public QWidget
34 | {
35 | Q_OBJECT
36 |
37 | static const int SAMPLE_DURATION;
38 | static const int WAVE_WIDTH;
39 | static const int WAVE_DURATION;
40 |
41 | public:
42 | Waveform(QWidget *parent = 0);
43 |
44 | static qreal getPeakValue(const QAudioFormat &format);
45 | static QVector getBufferLevels(const QAudioBuffer &buffer);
46 |
47 | template
48 | static QVector getBufferLevels(const T *buffer, int frames, int channels);
49 |
50 | void clearWave();
51 |
52 | public slots:
53 | void renderWave();
54 | void updateWave(float sample);
55 |
56 | protected:
57 | void paintEvent(QPaintEvent *event);
58 |
59 | private:
60 | QDateTime lastSampleTime;
61 | QList sampleList;
62 | QTimer *renderTimer;
63 | };
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/src/main_window.h:
--------------------------------------------------------------------------------
1 | /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
2 | * -*- coding: utf-8 -*-
3 | *
4 | * Copyright (C) 2011 ~ 2017 Deepin, Inc.
5 | * 2011 ~ 2017 Wang Yong
6 | *
7 | * Author: Wang Yong
8 | * Maintainer: Wang Yong
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program. If not, see .
22 | */
23 |
24 | #ifndef MAINWINDOW_H
25 | #define MAINWINDOW_H
26 |
27 | #include "ddialog.h"
28 | #include "dmainwindow.h"
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include "listen_voice.h"
35 | #include "waveform.h"
36 | #include
37 | #include
38 | #include "pinyin_widget.h"
39 |
40 | DWIDGET_USE_NAMESPACE
41 |
42 | class MainWindow : public DMainWindow
43 | {
44 | Q_OBJECT
45 |
46 | public:
47 | MainWindow(DMainWindow *parent = 0);
48 | ~MainWindow();
49 |
50 | bool eventFilter(QObject *, QEvent *);
51 | void paintEvent(QPaintEvent *);
52 |
53 | void startListen();
54 |
55 | public slots:
56 | void showPinyin(QString text);
57 | void renderLevel(const QAudioBuffer &buffer);
58 |
59 | private:
60 | ListenVoice listenVoice;
61 | QWidget *layoutWidget;
62 | QStackedLayout *stackedLayout;
63 | Waveform *waveform;
64 | QAudioProbe *audioProbe;
65 | QAudioRecorder *audioRecorder;
66 | float recordingTime;
67 | QDateTime lastUpdateTime;
68 | PinyinWidget *pinyinWidget;
69 | };
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/src/utils.h:
--------------------------------------------------------------------------------
1 | /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
2 | * -*- coding: utf-8 -*-
3 | *
4 | * Copyright (C) 2011 ~ 2017 Deepin, Inc.
5 | * 2011 ~ 2017 Wang Yong
6 | *
7 | * Author: Wang Yong
8 | * Maintainer: Wang Yong
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program. If not, see .
22 | */
23 | #ifndef UTILS_H
24 | #define UTILS_H
25 |
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | const int RECTANGLE_PADDING = 24;
33 | const int RECTANGLE_RADIUS = 8;
34 | const int RECTANGLE_FONT_SIZE = 11;
35 |
36 | namespace Utils {
37 | QSize getRenderSize(int fontSize, QString string);
38 | QString getImagePath(QString imageName);
39 | QString getQrcPath(QString imageName);
40 | QString getQssPath(QString qssName);
41 | bool fileExists(QString path);
42 | qreal easeInOut(qreal x);
43 | qreal easeInQuad(qreal x);
44 | qreal easeInQuint(qreal x);
45 | qreal easeOutQuad(qreal x);
46 | qreal easeOutQuint(qreal x);
47 | void addLayoutWidget(QLayout *layout, QWidget *widget);
48 | void applyQss(QWidget *widget, QString qssName);
49 | void drawLoadingRing(QPainter &painter,
50 | int centerX,
51 | int centerY,
52 | int radius,
53 | int penWidth,
54 | int loadingAngle,
55 | int rotationAngle,
56 | QString foregroundColor,
57 | double foregroundOpacity,
58 | QString backgroundColor,
59 | double backgroundOpacity,
60 | double percent);
61 | void drawRing(QPainter &painter, int centerX, int centerY, int radius, int penWidth, int loadingAngle, int rotationAngle, QString color, double opacity);
62 | void removeChildren(QWidget *widget);
63 | void removeLayoutChild(QLayout *layout, int index);
64 | void setFontSize(QPainter &painter, int textSize);
65 | }
66 |
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
1 | /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
2 | * -*- coding: utf-8 -*-
3 | *
4 | * Copyright (C) 2011 ~ 2017 Deepin, Inc.
5 | * 2011 ~ 2017 Wang Yong
6 | *
7 | * Author: Wang Yong
8 | * Maintainer: Wang Yong
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program. If not, see .
22 | */
23 |
24 | #include "utils.h"
25 | #include "main_window.h"
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 |
37 | DWIDGET_USE_NAMESPACE
38 |
39 | int main(int argc, char *argv[])
40 | {
41 | DApplication::loadDXcbPlugin();
42 |
43 | DApplication app(argc, argv);
44 |
45 | const QString socket_path(QString("deepin-pinyin-assistant"));
46 | if (app.setSingleInstance(socket_path)) {
47 | app.loadTranslator();
48 |
49 | const QString descriptionText = QApplication::tr("Deepin Font Installer is a simple font installer");
50 |
51 | const QString acknowledgementLink = "https://www.deepin.org/acknowledgments/deepin-pinyin-assistant#thanks";
52 |
53 | app.setOrganizationName("deepin");
54 | app.setApplicationName("deepin-pinyin-assistant");
55 | app.setApplicationDisplayName(QObject::tr("Deepin Font Installer"));
56 | app.setApplicationVersion("1.0");
57 |
58 | app.setProductIcon(QPixmap::fromImage(QImage(Utils::getQrcPath("logo_96.svg"))));
59 | app.setProductName(QApplication::tr("Deepin Font Installer"));
60 | app.setApplicationDescription(descriptionText);
61 | app.setApplicationAcknowledgementPage(acknowledgementLink);
62 |
63 | app.setWindowIcon(QIcon(Utils::getQrcPath("logo_48.png")));
64 |
65 | MainWindow window;
66 |
67 | QObject::connect(&app, &DApplication::newInstanceStarted, &window, &MainWindow::startListen);
68 |
69 | int width = 800;
70 | int height = 150;
71 | window.setFixedSize(width, height);
72 | window.move((QApplication::desktop()->screen()->rect().width() - width) / 2, 0);
73 | window.show();
74 |
75 | return app.exec();
76 | }
77 |
78 | return 0;
79 | }
80 |
--------------------------------------------------------------------------------
/deepin-pinyin-assistant.pro:
--------------------------------------------------------------------------------
1 | ######################################################################
2 | # Automatically generated by qmake (3.0) ?? 2? 4 17:49:37 2017
3 | ######################################################################
4 |
5 | TEMPLATE = app
6 | TARGET = deepin-pinyin-assistant
7 |
8 | CONFIG += link_pkgconfig
9 | CONFIG += c++11
10 | PKGCONFIG += xcb xcb-util dtkwidget libavformat libavcodec libavutil
11 | RESOURCES = deepin-pinyin-assistant.qrc
12 |
13 | CONFIG(debug, debug|release) {
14 | # Enable memory address sanitizer in debug mode.
15 | QMAKE_CXXFLAGS += -fsanitize=address
16 | LIBS += -lasan
17 | }
18 |
19 | # Input
20 | HEADERS += src/utils.h \
21 | src/speech_recognizer.h \
22 | src/linuxrec.h \
23 | src/formats.h \
24 | src/msp_cmn.h \
25 | src/msp_errors.h \
26 | src/msp_types.h \
27 | src/qise.h \
28 | src/qisr.h \
29 | src/qtts.h \
30 | src/listen_voice.h \
31 | src/waveform.h \
32 | src/chinese2pinyin.h \
33 | src/pinyin_widget.h \
34 | src/main_window.h
35 | SOURCES += src/main.cpp \
36 | src/speech_recognizer.c \
37 | src/linuxrec.c \
38 | src/listen_voice.cpp \
39 | src/waveform.cpp \
40 | src/chinese2pinyin.cpp \
41 | src/pinyin_widget.cpp \
42 | src/main_window.cpp \
43 | src/utils.cpp
44 |
45 | QT += core
46 | QT += widgets
47 | QT += gui
48 | QT += network
49 | QT += x11extras
50 | QT += dbus
51 | QT += multimedia
52 |
53 | QMAKE_CXXFLAGS += -g
54 | LIBS += -lX11 -lXext -lXtst -lmsc -lrt -ldl -lpthread -lasound
55 |
56 | OBJECTS_DIR=out
57 | MOC_DIR=out
58 |
59 | isEmpty(BINDIR):BINDIR=$${PREFIX}/bin
60 | isEmpty(ICONDIR):ICONDIR=$${PREFIX}/share/icons/hicolor/scalable/apps
61 | isEmpty(APPDIR):APPDIR=$${PREFIX}/share/applications
62 | isEmpty(DSRDIR):DSRDIR=$${PREFIX}/share/$${TARGET}
63 | isEmpty(DOCDIR):DOCDIR=$${PREFIX}/share/dman/$${TARGET}
64 | desktop.path = $$INSTROOT$$APPDIR
65 | icon.path = $$INSTROOT$$ICONDIR
66 | target.path = $$INSTROOT$$BINDIR
67 | translations.path = $$INSTROOT$$DSRDIR/translations
68 | manual.path = $$INSTROOT$$DOCDIR
69 |
70 | isEmpty(TRANSLATIONS) {
71 | include(translations.pri)
72 | }
73 |
74 | TRANSLATIONS_COMPILED = $$TRANSLATIONS
75 | TRANSLATIONS_COMPILED ~= s/\.ts/.qm/g
76 |
77 | desktop.files = deepin-pinyin-assistant.desktop
78 | icon.files = image/deepin-pinyin-assistant.svg
79 | translations.files = $$TRANSLATIONS_COMPILED
80 | manual.files = manual/*
81 |
82 | INSTALLS += desktop icon target translations manual
83 |
84 | CONFIG *= update_translations release_translations
85 |
86 | CONFIG(update_translations) {
87 | isEmpty(lupdate):lupdate=lupdate
88 | system($$lupdate -no-obsolete -locations none $$_PRO_FILE_)
89 | }
90 | CONFIG(release_translations) {
91 | isEmpty(lrelease):lrelease=lrelease
92 | system($$lrelease $$_PRO_FILE_)
93 | }
94 |
95 | DSR_LANG_PATH += $$DSRDIR/translations
96 | DEFINES += "DSR_LANG_PATH=\\\"$$DSR_LANG_PATH\\\""
97 |
--------------------------------------------------------------------------------
/src/linuxrec.h:
--------------------------------------------------------------------------------
1 | /*
2 | * @file
3 | * @brief a record demo in linux
4 | *
5 | * a simple record code. using alsa-lib APIs.
6 | * keep the function same as winrec.h
7 | *
8 | * Common steps:
9 | * create_recorder,
10 | * open_recorder,
11 | * start_record,
12 | * stop_record,
13 | * close_recorder,
14 | * destroy_recorder
15 | *
16 | * @author taozhang9
17 | * @date 2016/06/01
18 | */
19 |
20 | #ifndef __IFLY_WINREC_H__
21 | #define __IFLY_WINREC_H__
22 |
23 | #include "formats.h"
24 | /* error code */
25 | enum {
26 | RECORD_ERR_BASE = 0,
27 | RECORD_ERR_GENERAL,
28 | RECORD_ERR_MEMFAIL,
29 | RECORD_ERR_INVAL,
30 | RECORD_ERR_NOT_READY
31 | };
32 |
33 | typedef struct {
34 | union {
35 | char * name;
36 | int index;
37 | void * resv;
38 | }u;
39 | }record_dev_id;
40 |
41 | /* recorder object. */
42 | struct recorder {
43 | void (*on_data_ind)(char *data, unsigned long len, void *user_para);
44 | void * user_cb_para;
45 | volatile int state; /* internal record state */
46 |
47 | void * wavein_hdl;
48 | /* thread id may be a struct. by implementation
49 | * void * will not be ported!! */
50 | pthread_t rec_thread;
51 | /*void * rec_thread_hdl;*/
52 |
53 | void * bufheader;
54 | unsigned int bufcount;
55 |
56 | char *audiobuf;
57 | int bits_per_frame;
58 | unsigned int buffer_time;
59 | unsigned int period_time;
60 | size_t period_frames;
61 | size_t buffer_frames;
62 | };
63 |
64 | #ifdef __cplusplus
65 | extern "C" {
66 | #endif /* C++ */
67 |
68 | /**
69 | * @fn
70 | * @brief Get the default input device ID
71 | *
72 | * @return returns "default" in linux.
73 | *
74 | */
75 | record_dev_id get_default_input_dev();
76 |
77 | /**
78 | * @fn
79 | * @brief Get the total number of active input devices.
80 | * @return
81 | */
82 | int get_input_dev_num();
83 |
84 | /**
85 | * @fn
86 | * @brief Create a recorder object.
87 | *
88 | * Never call the close_recorder in the callback function. as close
89 | * action will wait for the callback thread to quit.
90 | *
91 | * @return int - Return 0 in success, otherwise return error code.
92 | * @param out_rec - [out] recorder object holder
93 | * @param on_data_ind - [in] callback. called when data coming.
94 | * @param user_cb_para - [in] user params for the callback.
95 | * @see
96 | */
97 | int create_recorder(struct recorder ** out_rec,
98 | void (*on_data_ind)(char *data, unsigned long len, void *user_para),
99 | void* user_cb_para);
100 |
101 | /**
102 | * @fn
103 | * @brief Destroy recorder object. free memory.
104 | * @param rec - [in]recorder object
105 | */
106 | void destroy_recorder(struct recorder *rec);
107 |
108 | /**
109 | * @fn
110 | * @brief open the device.
111 | * @return int - Return 0 in success, otherwise return error code.
112 | * @param rec - [in] recorder object
113 | * @param dev - [in] device id, from 0.
114 | * @param fmt - [in] record format.
115 | * @see
116 | * get_default_input_dev()
117 | */
118 | int open_recorder(struct recorder * rec, record_dev_id dev, WAVEFORMATEX * fmt);
119 |
120 | /**
121 | * @fn
122 | * @brief close the device.
123 | * @param rec - [in] recorder object
124 | */
125 |
126 | void close_recorder(struct recorder *rec);
127 |
128 | /**
129 | * @fn
130 | * @brief start record.
131 | * @return int - Return 0 in success, otherwise return error code.
132 | * @param rec - [in] recorder object
133 | */
134 | int start_record(struct recorder * rec);
135 |
136 | /**
137 | * @fn
138 | * @brief stop record.
139 | * @return int - Return 0 in success, otherwise return error code.
140 | * @param rec - [in] recorder object
141 | */
142 | int stop_record(struct recorder * rec);
143 |
144 | /**
145 | * @fn
146 | * @brief test if the recording has been stopped.
147 | * @return int - 1: stopped. 0 : recording.
148 | * @param rec - [in] recorder object
149 | */
150 | int is_record_stopped(struct recorder *rec);
151 |
152 | #ifdef __cplusplus
153 | } /* extern "C" */
154 | #endif /* C++ */
155 |
156 | #endif
157 |
--------------------------------------------------------------------------------
/src/listen_voice.cpp:
--------------------------------------------------------------------------------
1 | #include "listen_voice.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "qisr.h"
8 | #include "msp_cmn.h"
9 | #include "msp_errors.h"
10 | #include "speech_recognizer.h"
11 | #include
12 |
13 | #define FRAME_LEN 640
14 | #define BUFFER_SIZE 4096
15 |
16 | static char *recognizeResult = NULL;
17 | static unsigned int resultBufferSize = BUFFER_SIZE;
18 | static bool speakDone = false;
19 | static QString text = "";
20 |
21 | void ListenVoice::showResult(char *string, char)
22 | {
23 | text = QString::fromStdString(string);
24 | }
25 |
26 | void ListenVoice::resultHandler(const char *result, char isLast)
27 | {
28 | if (result) {
29 | size_t left = resultBufferSize - 1 - strlen(recognizeResult);
30 | size_t size = strlen(result);
31 | if (left < size) {
32 | recognizeResult = (char*)realloc(recognizeResult, resultBufferSize + BUFFER_SIZE);
33 | if (recognizeResult)
34 | resultBufferSize += BUFFER_SIZE;
35 | else {
36 | printf("mem alloc failed\n");
37 | return;
38 | }
39 | }
40 | strncat(recognizeResult, result, size);
41 | ListenVoice::showResult(recognizeResult, isLast);
42 | }
43 | }
44 |
45 | void ListenVoice::speechBeginHandler()
46 | {
47 | if (recognizeResult) {
48 | free(recognizeResult);
49 | }
50 |
51 | recognizeResult = (char*)malloc(BUFFER_SIZE);
52 | resultBufferSize = BUFFER_SIZE;
53 | memset(recognizeResult, 0, resultBufferSize);
54 |
55 | printf("Start Listening...\n");
56 | }
57 |
58 | void ListenVoice::speechEndHandler(int reason)
59 | {
60 | if (reason == END_REASON_VAD_DETECT) {
61 | printf("\nSpeaking done \n");
62 |
63 | speakDone = true;
64 | } else {
65 | printf("\nRecognizer error %d\n", reason);
66 | }
67 | }
68 |
69 | /* demo recognize the audio from microphone */
70 | void ListenVoice::listenFromMicrophone(const char* sessionBeginParams)
71 | {
72 | int errcode;
73 | int i = 0;
74 |
75 | struct speech_rec iat;
76 |
77 | struct speech_rec_notifier recnotifier = {
78 | ListenVoice::resultHandler,
79 | ListenVoice::speechBeginHandler,
80 | ListenVoice::speechEndHandler
81 | };
82 |
83 | errcode = sr_init(&iat, sessionBeginParams, SR_MIC, &recnotifier);
84 | if (errcode) {
85 | printf("speech recognizer init failed\n");
86 | return;
87 | }
88 |
89 | errcode = sr_start_listening(&iat);
90 | if (errcode) {
91 | printf("start listen failed %d\n", errcode);
92 | }
93 |
94 | /* demo 15 seconds recording */
95 | while (!speakDone && i++ < 15) {
96 | sleep(1);
97 | }
98 |
99 | errcode = sr_stop_listening(&iat);
100 | if (errcode) {
101 | printf("stop listening failed %d\n", errcode);
102 | }
103 |
104 | sr_uninit(&iat);
105 | }
106 |
107 | ListenVoice::ListenVoice(QObject *parent) : QThread(parent)
108 | {
109 |
110 | }
111 |
112 | void ListenVoice::run()
113 | {
114 | int ret = MSP_SUCCESS;
115 | const char* loginParams = "appid = 513e0a70, work_dir = .";
116 |
117 | /*
118 | * See "iFlytek MSC Reference Manual"
119 | */
120 | const char* sessionBeginParams =
121 | "sub = iat, domain = iat, language = zh_cn, "
122 | "accent = mandarin, sample_rate = 16000, "
123 | "result_type = plain, result_encoding = utf8";
124 |
125 | /* Login first. the 1st arg is username, the 2nd arg is password
126 | * just set them as NULL. the 3rd arg is login paramertes
127 | * */
128 | ret = MSPLogin(NULL, NULL, loginParams);
129 | if (MSP_SUCCESS != ret) {
130 | printf("MSPLogin failed , Error code %d.\n",ret);
131 | MSPLogout(); // Logout...
132 | return;
133 | }
134 |
135 | printf("Demo recognizing the speech from microphone\n");
136 | printf("Speak in 15 seconds\n");
137 |
138 | speakDone = false;
139 | text = "";
140 | ListenVoice::listenFromMicrophone(sessionBeginParams);
141 |
142 | voiceText(text);
143 | }
144 |
145 | void ListenVoice::startListen()
146 | {
147 | QThread::start();
148 | }
149 |
--------------------------------------------------------------------------------
/src/chinese2pinyin.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015 LiuLang. All rights reserved.
2 | // Use of this source is governed by General Public License that can be found
3 | // in the LICENSE file.
4 |
5 | #include "chinese2pinyin.h"
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | namespace Pinyin {
13 |
14 | static QHash dict = {};
15 |
16 | const char kDictFile[] = ":/misc/dict/pinyin.dict";
17 |
18 | void InitDict() {
19 | if (!dict.isEmpty()) {
20 | return;
21 | }
22 |
23 | dict.reserve(25333);
24 |
25 | QFile file(kDictFile);
26 |
27 | if (!file.open(QIODevice::ReadOnly)) {
28 | qCritical() << "open dict failed";
29 | return;
30 | }
31 |
32 | QByteArray content = file.readAll();
33 |
34 | file.close();
35 |
36 | QTextStream stream(&content, QIODevice::ReadOnly);
37 |
38 | while (!stream.atEnd()) {
39 | const QString line = stream.readLine();
40 | const QStringList items = line.split(QChar(':'));
41 |
42 | if (items.size() == 2) {
43 | dict.insert(items[0].toInt(nullptr, 16), items[1]);
44 | }
45 | }
46 | }
47 |
48 | QString Chinese2Pinyin(const QString& words) {
49 | InitDict();
50 |
51 | QString result;
52 |
53 | for (int i = 0; i < words.length(); ++i) {
54 | const uint key = words.at(i).unicode();
55 | auto find_result = dict.find(key);
56 |
57 | if (find_result != dict.end()) {
58 | result.append(find_result.value());
59 | } else {
60 | result.append(words.at(i));
61 | }
62 | }
63 |
64 | return result;
65 | }
66 |
67 | inline bool isAlphabeta(const QChar &c)
68 | {
69 | QRegExp re("[A-Za-z]*");
70 | return re.exactMatch(c);
71 | }
72 |
73 | inline bool isNumber(const QChar &c)
74 | {
75 | QRegExp re("[0-9]*");
76 | return re.exactMatch(c);
77 | }
78 |
79 | inline bool isChinese(const QChar &c)
80 | {
81 | return c.unicode() < 0x9FBF && c.unicode() > 0x4E00;
82 | }
83 |
84 | inline QString toChinesePinyin(const QString &c)
85 | {
86 | QString pinyin = Pinyin::Chinese2Pinyin(c);
87 | if (pinyin.length() >= 2
88 | && isNumber(pinyin.at(pinyin.length() - 1))) {
89 | return pinyin.left(pinyin.length() - 1);
90 | }
91 | return pinyin;
92 | }
93 |
94 | QStringList splitChineseToPinyin(QString &pinyin)
95 | {
96 | QStringList wordList;
97 | bool isLastAlphabeta = false;
98 | for (auto &c : pinyin) {
99 | bool isCurAlphabeta = isAlphabeta(c);
100 | if (isCurAlphabeta) {
101 | if (!isLastAlphabeta) {
102 | wordList << c;
103 | } else {
104 | wordList.last().append(c);
105 | }
106 | continue;
107 | }
108 | isLastAlphabeta = isCurAlphabeta;
109 | if (isNumber(c)) {
110 | wordList << c;
111 | continue;
112 | }
113 | if (isChinese(c)) {
114 | wordList << toChinesePinyin(c);
115 | continue;
116 | }
117 | }
118 | return wordList;
119 | }
120 |
121 | QStringList splitChinese(QString &pinyin)
122 | {
123 | QStringList wordList;
124 | bool isLastAlphabeta = false;
125 | for (auto &c : pinyin) {
126 | bool isCurAlphabeta = isAlphabeta(c);
127 | if (isCurAlphabeta) {
128 | if (!isLastAlphabeta) {
129 | wordList << c;
130 | } else {
131 | wordList.last().append(c);
132 | }
133 | continue;
134 | }
135 | isLastAlphabeta = isCurAlphabeta;
136 | if (isNumber(c)) {
137 | wordList << c;
138 | continue;
139 | }
140 | if (isChinese(c)) {
141 | wordList << c;
142 | continue;
143 | }
144 | }
145 | return wordList;
146 | }
147 | } // namespace Pinyin end
148 |
--------------------------------------------------------------------------------
/src/main_window.cpp:
--------------------------------------------------------------------------------
1 | /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
2 | * -*- coding: utf-8 -*-
3 | *
4 | * Copyright (C) 2011 ~ 2017 Deepin, Inc.
5 | * 2011 ~ 2017 Wang Yong
6 | *
7 | * Author: Wang Yong
8 | * Maintainer: Wang Yong
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program. If not, see .
22 | */
23 |
24 | #include "dthememanager.h"
25 | #include "dwindowmanagerhelper.h"
26 | #include "main_window.h"
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include "chinese2pinyin.h"
36 |
37 | using namespace std;
38 | using namespace Pinyin;
39 |
40 | MainWindow::MainWindow(DMainWindow *parent) : DMainWindow(parent)
41 | {
42 | // Init.
43 | installEventFilter(this); // add event filter
44 | setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus | Qt::BypassWindowManagerHint);
45 |
46 | // Init titlebar.
47 | if (this->titlebar()) {
48 | this->titlebar()->setWindowFlags(Qt::WindowCloseButtonHint);
49 | }
50 |
51 | // Init background.
52 | DThemeManager::instance()->setTheme("light");
53 | setAttribute(Qt::WA_TranslucentBackground);
54 | setEnableBlurWindow(true);
55 | setTranslucentBackground(true);
56 |
57 | // Init time.
58 | recordingTime = 0;
59 |
60 |
61 | // Init widget.
62 | waveform = new Waveform();
63 | pinyinWidget = new PinyinWidget();
64 |
65 | layoutWidget = new QWidget();
66 | this->setCentralWidget(layoutWidget);
67 |
68 | stackedLayout = new QStackedLayout();
69 | layoutWidget->setLayout(stackedLayout);
70 |
71 | stackedLayout->addWidget(waveform);
72 | stackedLayout->addWidget(pinyinWidget);
73 |
74 | // Init audio recorder.
75 | audioRecorder = new QAudioRecorder(this);
76 |
77 | QAudioEncoderSettings audioSettings;
78 | audioSettings.setCodec("audio/PCM");
79 | audioSettings.setQuality(QMultimedia::HighQuality);
80 | audioRecorder->setEncodingSettings(audioSettings);
81 | audioRecorder->setContainerFormat("wav");
82 |
83 | audioProbe = new QAudioProbe(this);
84 | if (audioProbe->setSource(audioRecorder)) {
85 | connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(renderLevel(QAudioBuffer)));
86 | }
87 |
88 | // Start listen.
89 | connect(&listenVoice, &ListenVoice::voiceText, this, &MainWindow::showPinyin, Qt::QueuedConnection);
90 | startListen();
91 | }
92 |
93 | MainWindow::~MainWindow()
94 | {
95 | // We don't need clean pointers because application has exit here.
96 | }
97 |
98 | void MainWindow::startListen()
99 | {
100 | qDebug() << "Start listen";
101 |
102 | stackedLayout->setCurrentIndex(0);
103 |
104 | QDateTime currentTime = QDateTime::currentDateTime();
105 | lastUpdateTime = currentTime;
106 | audioRecorder->record();
107 | listenVoice.startListen();
108 | }
109 |
110 | void MainWindow::showPinyin(QString text)
111 | {
112 | stackedLayout->setCurrentIndex(1);
113 |
114 | pinyinWidget->setPinyin(Pinyin::splitChinese(text), Pinyin::splitChineseToPinyin(text));
115 | }
116 |
117 | bool MainWindow::eventFilter(QObject *, QEvent *event)
118 | {
119 | if (event->type() == QEvent::MouseButtonPress) {
120 | QApplication::quit();
121 | }
122 |
123 | return false;
124 | }
125 |
126 | void MainWindow::paintEvent(QPaintEvent *)
127 | {
128 |
129 | }
130 |
131 | void MainWindow::renderLevel(const QAudioBuffer &buffer)
132 | {
133 | QDateTime currentTime = QDateTime::currentDateTime();
134 | recordingTime += lastUpdateTime.msecsTo(currentTime);
135 | lastUpdateTime = currentTime;
136 |
137 | QVector levels = Waveform::getBufferLevels(buffer);
138 | for (int i = 0; i < levels.count(); ++i) {
139 | waveform->updateWave(levels.at(i));
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/utils.cpp:
--------------------------------------------------------------------------------
1 | /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
2 | * -*- coding: utf-8 -*-
3 | *
4 | * Copyright (C) 2011 ~ 2017 Deepin, Inc.
5 | * 2011 ~ 2017 Wang Yong
6 | *
7 | * Author: Wang Yong
8 | * Maintainer: Wang Yong
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program. If not, see .
22 | */
23 |
24 | #include "utils.h"
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #include
47 |
48 | namespace Utils {
49 | QSize getRenderSize(int fontSize, QString string)
50 | {
51 | QFont font;
52 | font.setPointSize(fontSize);
53 | QFontMetrics fm(font);
54 |
55 | int width = 0;
56 | int height = 0;
57 | foreach (auto line, string.split("\n")) {
58 | int lineWidth = fm.width(line);
59 | int lineHeight = fm.height();
60 |
61 | if (lineWidth > width) {
62 | width = lineWidth;
63 | }
64 | height += lineHeight;
65 | }
66 |
67 | return QSize(width, height);
68 | }
69 |
70 | QString getImagePath(QString imageName)
71 | {
72 | QDir dir(qApp->applicationDirPath());
73 | dir.cdUp();
74 |
75 | return QDir(dir.filePath("image")).filePath(imageName);
76 | }
77 |
78 |
79 | QString getQrcPath(QString imageName)
80 | {
81 | return QString(":/image/%1").arg(imageName);
82 | }
83 |
84 | QString getQssPath(QString qssName)
85 | {
86 | return QString(":/qss/%1").arg(qssName);
87 | }
88 |
89 | bool fileExists(QString path)
90 | {
91 | QFileInfo check_file(path);
92 |
93 | // check if file exists and if yes: Is it really a file and no directory?
94 | return check_file.exists() && check_file.isFile();
95 | }
96 |
97 | qreal easeInOut(qreal x)
98 | {
99 | return (1 - qCos(M_PI * x)) / 2;
100 | }
101 |
102 | qreal easeInQuad(qreal x)
103 | {
104 | return qPow(x, 2);
105 | }
106 |
107 | qreal easeOutQuad(qreal x)
108 | {
109 | return -1 * qPow(x - 1, 2) + 1;
110 | }
111 |
112 | qreal easeInQuint(qreal x)
113 | {
114 | return qPow(x, 5);
115 | }
116 |
117 | qreal easeOutQuint(qreal x)
118 | {
119 | return qPow(x - 1, 5) + 1;
120 | }
121 |
122 | void addLayoutWidget(QLayout *layout, QWidget *widget)
123 | {
124 | layout->addWidget(widget);
125 | widget->show();
126 | }
127 |
128 | void applyQss(QWidget *widget, QString qssName)
129 | {
130 | QFile file(getQssPath(qssName));
131 | file.open(QFile::ReadOnly);
132 | QTextStream filetext(&file);
133 | QString stylesheet = filetext.readAll();
134 | widget->setStyleSheet(stylesheet);
135 | file.close();
136 | }
137 |
138 | void removeChildren(QWidget *widget)
139 | {
140 | qDeleteAll(widget->children());
141 | }
142 |
143 | void removeLayoutChild(QLayout *layout, int index)
144 | {
145 | QLayoutItem *item = layout->itemAt(index);
146 | if (item != 0) {
147 | QWidget *widget = item->widget();
148 | if (widget != NULL) {
149 | widget->hide();
150 | widget->setParent(NULL);
151 | layout->removeWidget(widget);
152 | }
153 | }
154 | }
155 |
156 | void setFontSize(QPainter &painter, int textSize)
157 | {
158 | QFont font = painter.font() ;
159 | font.setPointSize(textSize);
160 | painter.setFont(font);
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/src/msp_types.h:
--------------------------------------------------------------------------------
1 | #ifndef __MSP_TYPES_H__
2 | #define __MSP_TYPES_H__
3 |
4 | #if !defined(MSPAPI)
5 | #if defined(WIN32) || defined(WINPHONE8) || defined(WIN8)
6 | #define MSPAPI __stdcall
7 | #else
8 | #define MSPAPI
9 | #endif /* WIN32 */
10 | #endif /* MSPAPI */
11 |
12 |
13 | /**
14 | * MSPSampleStatus indicates how the sample buffer should be handled
15 | * MSP_AUDIO_SAMPLE_FIRST - The sample buffer is the start of audio
16 | * If recognizer was already recognizing, it will discard
17 | * audio received to date and re-start the recognition
18 | * MSP_AUDIO_SAMPLE_CONTINUE - The sample buffer is continuing audio
19 | * MSP_AUDIO_SAMPLE_LAST - The sample buffer is the end of audio
20 | * The recognizer will cease processing audio and
21 | * return results
22 | * Note that sample statii can be combined; for example, for file-based input
23 | * the entire file can be written with SAMPLE_FIRST | SAMPLE_LAST as the
24 | * status.
25 | * Other flags may be added in future to indicate other special audio
26 | * conditions such as the presence of AGC
27 | */
28 | enum
29 | {
30 | MSP_AUDIO_SAMPLE_INIT = 0x00,
31 | MSP_AUDIO_SAMPLE_FIRST = 0x01,
32 | MSP_AUDIO_SAMPLE_CONTINUE = 0x02,
33 | MSP_AUDIO_SAMPLE_LAST = 0x04,
34 | };
35 |
36 | /*
37 | * The enumeration MSPRecognizerStatus contains the recognition status
38 | * MSP_REC_STATUS_SUCCESS - successful recognition with partial results
39 | * MSP_REC_STATUS_NO_MATCH - recognition rejected
40 | * MSP_REC_STATUS_INCOMPLETE - recognizer needs more time to compute results
41 | * MSP_REC_STATUS_NON_SPEECH_DETECTED - discard status, no more in use
42 | * MSP_REC_STATUS_SPEECH_DETECTED - recognizer has detected audio, this is delayed status
43 | * MSP_REC_STATUS_COMPLETE - recognizer has return all result
44 | * MSP_REC_STATUS_MAX_CPU_TIME - CPU time limit exceeded
45 | * MSP_REC_STATUS_MAX_SPEECH - maximum speech length exceeded, partial results may be returned
46 | * MSP_REC_STATUS_STOPPED - recognition was stopped
47 | * MSP_REC_STATUS_REJECTED - recognizer rejected due to low confidence
48 | * MSP_REC_STATUS_NO_SPEECH_FOUND - recognizer still found no audio, this is delayed status
49 | */
50 | enum
51 | {
52 | MSP_REC_STATUS_SUCCESS = 0,
53 | MSP_REC_STATUS_NO_MATCH = 1,
54 | MSP_REC_STATUS_INCOMPLETE = 2,
55 | MSP_REC_STATUS_NON_SPEECH_DETECTED = 3,
56 | MSP_REC_STATUS_SPEECH_DETECTED = 4,
57 | MSP_REC_STATUS_COMPLETE = 5,
58 | MSP_REC_STATUS_MAX_CPU_TIME = 6,
59 | MSP_REC_STATUS_MAX_SPEECH = 7,
60 | MSP_REC_STATUS_STOPPED = 8,
61 | MSP_REC_STATUS_REJECTED = 9,
62 | MSP_REC_STATUS_NO_SPEECH_FOUND = 10,
63 | MSP_REC_STATUS_FAILURE = MSP_REC_STATUS_NO_MATCH,
64 | };
65 |
66 | /**
67 | * The enumeration MSPepState contains the current endpointer state
68 | * MSP_EP_LOOKING_FOR_SPEECH - Have not yet found the beginning of speech
69 | * MSP_EP_IN_SPEECH - Have found the beginning, but not the end of speech
70 | * MSP_EP_AFTER_SPEECH - Have found the beginning and end of speech
71 | * MSP_EP_TIMEOUT - Have not found any audio till timeout
72 | * MSP_EP_ERROR - The endpointer has encountered a serious error
73 | * MSP_EP_MAX_SPEECH - Have arrive the max size of speech
74 | */
75 | enum
76 | {
77 | MSP_EP_LOOKING_FOR_SPEECH = 0,
78 | MSP_EP_IN_SPEECH = 1,
79 | MSP_EP_AFTER_SPEECH = 3,
80 | MSP_EP_TIMEOUT = 4,
81 | MSP_EP_ERROR = 5,
82 | MSP_EP_MAX_SPEECH = 6,
83 | MSP_EP_IDLE = 7 // internal state after stop and before start
84 | };
85 |
86 | /* Synthesizing process flags */
87 | enum
88 | {
89 | MSP_TTS_FLAG_STILL_HAVE_DATA = 1,
90 | MSP_TTS_FLAG_DATA_END = 2,
91 | MSP_TTS_FLAG_CMD_CANCELED = 4,
92 | };
93 |
94 | /* Handwriting process flags */
95 | enum
96 | {
97 | MSP_HCR_DATA_FIRST = 1,
98 | MSP_HCR_DATA_CONTINUE = 2,
99 | MSP_HCR_DATA_END = 4,
100 | };
101 |
102 | /*ivw message type */
103 | enum
104 | {
105 | MSP_IVW_MSG_WAKEUP = 1,
106 | MSP_IVW_MSG_ERROR = 2,
107 | MSP_IVW_MSG_ISR_RESULT = 3,
108 | MSP_IVW_MSG_ISR_EPS = 4,
109 | MSP_IVW_MSG_VOLUME = 5,
110 | MSP_IVW_MSG_ENROLL = 6,
111 | MSP_IVW_MSG_RESET = 7
112 | };
113 |
114 | /* Upload data process flags */
115 | enum
116 | {
117 | MSP_DATA_SAMPLE_INIT = 0x00,
118 | MSP_DATA_SAMPLE_FIRST = 0x01,
119 | MSP_DATA_SAMPLE_CONTINUE = 0x02,
120 | MSP_DATA_SAMPLE_LAST = 0x04,
121 | };
122 |
123 | #endif /* __MSP_TYPES_H__ */
124 |
--------------------------------------------------------------------------------
/src/waveform.cpp:
--------------------------------------------------------------------------------
1 | /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
2 | * -*- coding: utf-8 -*-
3 | *
4 | * Copyright (C) 2011 ~ 2017 Deepin, Inc.
5 | * 2011 ~ 2017 Wang Yong
6 | *
7 | * Author: Wang Yong
8 | * Maintainer: Wang Yong
9 | *
10 | * This program is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program. If not, see .
22 | */
23 |
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 | #include "waveform.h"
34 |
35 | const int Waveform::SAMPLE_DURATION = 30;
36 | const int Waveform::WAVE_WIDTH = 2;
37 | const int Waveform::WAVE_DURATION = 4;
38 |
39 | Waveform::Waveform(QWidget *parent) : QWidget(parent)
40 | {
41 | setFixedSize(800, 71);
42 |
43 | lastSampleTime = QDateTime::currentDateTime();
44 |
45 | renderTimer = new QTimer();
46 | connect(renderTimer, SIGNAL(timeout()), this, SLOT(renderWave()));
47 | renderTimer->start(SAMPLE_DURATION);
48 | }
49 |
50 | void Waveform::paintEvent(QPaintEvent *)
51 | {
52 | QPainter painter(this);
53 | painter.setRenderHint(QPainter::Antialiasing, true);
54 |
55 | // Background render just for test.
56 | // QRect testRect(rect());
57 | // QLinearGradient testGradient(testRect.topLeft(), testRect.bottomLeft());
58 | // testGradient.setColorAt(0, QColor("#0000ff"));
59 | // testGradient.setColorAt(1, QColor("#00ff00"));
60 | // painter.fillRect(testRect, testGradient);
61 |
62 | int volume = 0;
63 | for (int i = 0; i < sampleList.size(); i++) {
64 | volume = sampleList[i] * rect().height() * 2;
65 |
66 | if (volume == 0) {
67 | QPainterPath path;
68 | path.addRect(QRectF(rect().x() + i * WAVE_DURATION, rect().y() + (rect().height() - 1) / 2, WAVE_DURATION, 1));
69 | painter.fillPath(path, QColor("#FFA0A0"));
70 | } else {
71 | QRect sampleRect(rect().x() + i * WAVE_DURATION, rect().y() + (rect().height() - volume) / 2, WAVE_WIDTH, volume);
72 |
73 | QLinearGradient gradient(sampleRect.topLeft(), sampleRect.bottomLeft());
74 | gradient.setColorAt(0, QColor("#FFBD78"));
75 | gradient.setColorAt(1, QColor("#FF005C"));
76 | painter.fillRect(sampleRect, gradient);
77 | }
78 | }
79 |
80 | if (sampleList.size() < rect().width() / WAVE_DURATION) {
81 | QPainterPath path;
82 | path.addRect(QRectF(rect().x() + sampleList.size() * WAVE_DURATION,
83 | rect().y() + (rect().height() - 1) / 2,
84 | rect().width() - (rect().x() + sampleList.size() * WAVE_DURATION),
85 | 1));
86 | painter.fillPath(path, QColor("#FFA0A0"));
87 | }
88 | }
89 |
90 | void Waveform::updateWave(float sample)
91 | {
92 | QDateTime currentTime = QDateTime::currentDateTime();
93 |
94 | if (lastSampleTime.msecsTo(currentTime) > SAMPLE_DURATION) {
95 | if (sampleList.size() > rect().width() / WAVE_DURATION) {
96 | sampleList.pop_front();
97 | }
98 | sampleList << sample;
99 |
100 | lastSampleTime = currentTime;
101 | }
102 | }
103 |
104 | void Waveform::renderWave()
105 | {
106 | repaint();
107 | }
108 |
109 | void Waveform::clearWave()
110 | {
111 | sampleList.clear();
112 | }
113 |
114 | // returns the audio level for each channel
115 | QVector Waveform::getBufferLevels(const QAudioBuffer& buffer)
116 | {
117 | QVector values;
118 |
119 | if (!buffer.format().isValid() || buffer.format().byteOrder() != QAudioFormat::LittleEndian)
120 | return values;
121 |
122 | if (buffer.format().codec() != "audio/pcm")
123 | return values;
124 |
125 | int channelCount = buffer.format().channelCount();
126 | values.fill(0, channelCount);
127 | qreal peak_value = Waveform::getPeakValue(buffer.format());
128 | if (qFuzzyCompare(peak_value, qreal(0)))
129 | return values;
130 |
131 | switch (buffer.format().sampleType()) {
132 | case QAudioFormat::Unknown:
133 | case QAudioFormat::UnSignedInt:
134 | if (buffer.format().sampleSize() == 32)
135 | values = Waveform::getBufferLevels(buffer.constData(), buffer.frameCount(), channelCount);
136 | if (buffer.format().sampleSize() == 16)
137 | values = Waveform::getBufferLevels(buffer.constData(), buffer.frameCount(), channelCount);
138 | if (buffer.format().sampleSize() == 8)
139 | values = Waveform::getBufferLevels(buffer.constData(), buffer.frameCount(), channelCount);
140 | for (int i = 0; i < values.size(); ++i)
141 | values[i] = qAbs(values.at(i) - peak_value / 2) / (peak_value / 2);
142 | break;
143 | case QAudioFormat::Float:
144 | if (buffer.format().sampleSize() == 32) {
145 | values = Waveform::getBufferLevels(buffer.constData(), buffer.frameCount(), channelCount);
146 | for (int i = 0; i < values.size(); ++i)
147 | values[i] /= peak_value;
148 | }
149 | break;
150 | case QAudioFormat::SignedInt:
151 | if (buffer.format().sampleSize() == 32)
152 | values = Waveform::getBufferLevels(buffer.constData(), buffer.frameCount(), channelCount);
153 | if (buffer.format().sampleSize() == 16)
154 | values = Waveform::getBufferLevels(buffer.constData(), buffer.frameCount(), channelCount);
155 | if (buffer.format().sampleSize() == 8)
156 | values = Waveform::getBufferLevels(buffer.constData(), buffer.frameCount(), channelCount);
157 | for (int i = 0; i < values.size(); ++i)
158 | values[i] /= peak_value;
159 | break;
160 | }
161 |
162 | return values;
163 | }
164 |
165 | template
166 | QVector Waveform::getBufferLevels(const T *buffer, int frames, int channels)
167 | {
168 | QVector max_values;
169 | max_values.fill(0, channels);
170 |
171 | for (int i = 0; i < frames; ++i) {
172 | for (int j = 0; j < channels; ++j) {
173 | qreal value = qAbs(qreal(buffer[i * channels + j]));
174 | if (value > max_values.at(j))
175 | max_values.replace(j, value);
176 | }
177 | }
178 |
179 | return max_values;
180 | }
181 |
182 | // This function returns the maximum possible sample value for a given audio format
183 | qreal Waveform::getPeakValue(const QAudioFormat& format)
184 | {
185 | // Note: Only the most common sample formats are supported
186 | if (!format.isValid())
187 | return qreal(0);
188 |
189 | if (format.codec() != "audio/pcm")
190 | return qreal(0);
191 |
192 | switch (format.sampleType()) {
193 | case QAudioFormat::Unknown:
194 | break;
195 | case QAudioFormat::Float:
196 | if (format.sampleSize() != 32) // other sample formats are not supported
197 | return qreal(0);
198 | return qreal(1.00003);
199 | case QAudioFormat::SignedInt:
200 | if (format.sampleSize() == 32)
201 | return qreal(INT_MAX);
202 | if (format.sampleSize() == 16)
203 | return qreal(SHRT_MAX);
204 | if (format.sampleSize() == 8)
205 | return qreal(CHAR_MAX);
206 | break;
207 | case QAudioFormat::UnSignedInt:
208 | if (format.sampleSize() == 32)
209 | return qreal(UINT_MAX);
210 | if (format.sampleSize() == 16)
211 | return qreal(USHRT_MAX);
212 | if (format.sampleSize() == 8)
213 | return qreal(UCHAR_MAX);
214 | break;
215 | }
216 |
217 | return qreal(0);
218 | }
219 |
--------------------------------------------------------------------------------
/src/qtts.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file qtts.h
3 | * @brief iFLY Speech Synthesizer Header File
4 | *
5 | * This file contains the quick application programming interface (API) declarations
6 | * of TTS. Developer can include this file in your project to build applications.
7 | * For more information, please read the developer guide.
8 |
9 | * Use of this software is subject to certain restrictions and limitations set
10 | * forth in a license agreement entered into between iFLYTEK, Co,LTD.
11 | * and the licensee of this software. Please refer to the license
12 | * agreement for license use rights and restrictions.
13 | *
14 | * Copyright (C) 1999 - 2009 by ANHUI USTC iFLYTEK, Co,LTD.
15 | * All rights reserved.
16 | *
17 | * @author Speech Dept.
18 | * @version 1.0
19 | * @date 2009/11/26
20 | *
21 | * @see
22 | *
23 | * History:
24 | *
25 | * | Version | Date | Author | Notes |
26 | * | 1.0 | 2009/11/26 | Speech | Create this file |
27 | *
28 | *
29 | */
30 | #ifndef __QTTS_H__
31 | #define __QTTS_H__
32 |
33 | #if !defined(MSPAPI)
34 | #if defined(WIN32)
35 | #define MSPAPI __stdcall
36 | #else
37 | #define MSPAPI
38 | #endif /* WIN32 */
39 | #endif /* MSPAPI */
40 |
41 | #ifdef __cplusplus
42 | extern "C" {
43 | #endif /* C++ */
44 |
45 | #include "msp_types.h"
46 |
47 | /**
48 | * @fn QTTSSessionBegin
49 | * @brief Begin a TTS Session
50 | *
51 | * Create a tts session to synthesize data.
52 | *
53 | * @return const char* - Return the new session id in success, otherwise return NULL, error code.
54 | * @param const char* params - [in] parameters when the session created.
55 | * @param const char** sessionID - [out] return a string to this session.
56 | * @see
57 | */
58 | const char* MSPAPI QTTSSessionBegin(const char* params, int* errorCode);
59 | typedef const char* (MSPAPI *Proc_QTTSSessionBegin)(const char* params, int* errorCode);
60 | #ifdef MSP_WCHAR_SUPPORT
61 | const wchar_t* MSPAPI QTTSSessionBeginW(const wchar_t* params, int* errorCode);
62 | typedef const wchar_t* (MSPAPI *Proc_QTTSSessionBeginW)(const wchar_t* params, int* errorCode);
63 | #endif
64 |
65 | /**
66 | * @fn QTTSTextPut
67 | * @brief Put Text Buffer to TTS Session
68 | *
69 | * Writing text string to synthesizer.
70 | *
71 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
72 | * @param const char* sessionID - [in] The session id returned by sesson begin
73 | * @param const char* textString - [in] text buffer
74 | * @param unsigned int textLen - [in] text size in bytes
75 | * @see
76 | */
77 | int MSPAPI QTTSTextPut(const char* sessionID, const char* textString, unsigned int textLen, const char* params);
78 | typedef int (MSPAPI *Proc_QTTSTextPut)(const char* sessionID, const char* textString, unsigned int textLen, const char* params);
79 | #ifdef MSP_WCHAR_SUPPORT
80 | int MSPAPI QTTSTextPutW(const wchar_t* sessionID, const wchar_t* textString, unsigned int textLen, const wchar_t* params);
81 | typedef int (MSPAPI *Proc_QTTSTextPutW)(const wchar_t* sessionID, const wchar_t* textString, unsigned int textLen, const wchar_t* params);
82 | #endif
83 |
84 | /**
85 | * @fn QTTSAudioGet
86 | * @brief Synthesize text to audio
87 | *
88 | * Synthesize text to audio, and return audio information.
89 | *
90 | * @return const void* - Return current synthesized audio data buffer, size returned by QTTSTextSynth.
91 | * @param const char* sessionID - [in] session id returned by session begin
92 | * @param unsigned int* audioLen - [out] synthesized audio size in bytes
93 | * @param int* synthStatus - [out] synthesizing status
94 | * @param int* errorCode - [out] error code if failed, 0 to success.
95 | * @see
96 | */
97 | const void* MSPAPI QTTSAudioGet(const char* sessionID, unsigned int* audioLen, int* synthStatus, int* errorCode);
98 | typedef const void* (MSPAPI *Proc_QTTSAudioGet)(const char* sessionID, unsigned int* audioLen, int* synthStatus, int* errorCode);
99 | #ifdef MSP_WCHAR_SUPPORT
100 | const void* MSPAPI QTTSAudioGetW(const wchar_t* sessionID, unsigned int* audioLen, int* synthStatus, int* errorCode);
101 | typedef const void* (MSPAPI *Proc_QTTSAudioGetW)(const wchar_t* sessionID, unsigned int* audioLen, int* synthStatus, int* errorCode);
102 | #endif
103 |
104 | /**
105 | * @fn QTTSAudioInfo
106 | * @brief Get Synthesized Audio information
107 | *
108 | * Get synthesized audio data information.
109 | *
110 | * @return const char * - Return audio info string.
111 | * @param const char* sessionID - [in] session id returned by session begin
112 | * @see
113 | */
114 | const char* MSPAPI QTTSAudioInfo(const char* sessionID);
115 | typedef const char* (MSPAPI *Proc_QTTSAudioInfo)(const char* sessionID);
116 | #ifdef MSP_WCHAR_SUPPORT
117 | const wchar_t* MSPAPI QTTSAudioInfoW(const wchar_t* sessionID);
118 | typedef const wchar_t* (MSPAPI *Proc_QTTSAudioInfoW)(const wchar_t* sessionID);
119 | #endif
120 |
121 | /**
122 | * @fn QTTSSessionEnd
123 | * @brief End a Recognizer Session
124 | *
125 | * End the recognizer session, release all resource.
126 | *
127 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
128 | * @param const char* session_id - [in] session id string to end
129 | * @param const char* hints - [in] user hints to end session, hints will be logged to CallLog
130 | * @see
131 | */
132 | int MSPAPI QTTSSessionEnd(const char* sessionID, const char* hints);
133 | typedef int (MSPAPI *Proc_QTTSSessionEnd)(const char* sessionID, const char* hints);
134 | #ifdef MSP_WCHAR_SUPPORT
135 | int MSPAPI QTTSSessionEndW(const wchar_t* sessionID, const wchar_t* hints);
136 | typedef int (MSPAPI *Proc_QTTSSessionEndW)(const wchar_t* sessionID, const wchar_t* hints);
137 | #endif
138 |
139 | /**
140 | * @fn QTTSGetParam
141 | * @brief get params related with msc
142 | *
143 | * the params could be local or server param, we only support netflow params "upflow" & "downflow" now
144 | *
145 | * @return int - Return 0 if success, otherwise return errcode.
146 | * @param const char* sessionID - [in] session id of related param, set NULL to got global param
147 | * @param const char* paramName - [in] param name,could pass more than one param split by ','';'or'\n'
148 | * @param const char* paramValue - [in] param value buffer, malloced by user
149 | * @param int *valueLen - [in, out] pass in length of value buffer, and return length of value string
150 | * @see
151 | */
152 | int MSPAPI QTTSGetParam(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
153 | typedef int (MSPAPI *Proc_QTTSGetParam)(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
154 | #ifdef MSP_WCHAR_SUPPORT
155 | int MSPAPI QTTSGetParamW(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue, unsigned int* valueLen);
156 | typedef int (MSPAPI *Proc_QTTSGetParamW)(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue, unsigned int* valueLen);
157 | #endif
158 |
159 | /**
160 | * @fn QTTSSetParam
161 | * @brief set params related with msc
162 | *
163 | * the params could be local or server param, we only support netflow params "upflow" & "downflow" now
164 | *
165 | * @return int - Return 0 if success, otherwise return errcode.
166 | * @param const char* sessionID - [in] session id of related param, set NULL to got global param
167 | * @param const char* paramName - [in] param name,could pass more than one param split by ','';'or'\n'
168 | * @param const char* paramValue - [in] param value buffer, malloced by user
169 | * @see
170 | */
171 | int MSPAPI QTTSSetParam(const char *sessionID, const char *paramName, const char *paramValue);
172 | typedef int (MSPAPI *Proc_QTTSSetParam)(const char* sessionID, const char* paramName, char* paramValue);
173 | #ifdef MSP_WCHAR_SUPPORT
174 | int MSPAPI QTTSSetParamW(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue);
175 | typedef int (MSPAPI *Proc_QTTSSetParamW)(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue);
176 | #endif
177 |
178 | typedef void ( *tts_result_ntf_handler)( const char *sessionID, const char *audio, int audioLen, int synthStatus, int ced, const char *audioInfo, int audioInfoLen, void *userData );
179 | typedef void ( *tts_status_ntf_handler)( const char *sessionID, int type, int status, int param1, const void *param2, void *userData);
180 | typedef void ( *tts_error_ntf_handler)(const char *sessionID, int errorCode, const char *detail, void *userData);
181 | int MSPAPI QTTSRegisterNotify(const char *sessionID, tts_result_ntf_handler rsltCb, tts_status_ntf_handler statusCb, tts_error_ntf_handler errCb, void *userData);
182 |
183 | #ifdef __cplusplus
184 | } /* extern "C" */
185 | #endif /* C++ */
186 |
187 | #endif /* __QTTS_H__ */
188 |
--------------------------------------------------------------------------------
/src/qise.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file qise.h
3 | * @brief iFLY Speech Evaluation Header File
4 | *
5 | * This file contains the quick application programming interface (API) declarations
6 | * of evaluation. Developer can include this file in your project to build applications.
7 | * For more information, please read the developer guide.
8 |
9 | * Use of this software is subject to certain restrictions and limitations set
10 | * forth in a license agreement entered into between iFLYTEK, Co,LTD.
11 | * and the licensee of this software. Please refer to the license
12 | * agreement for license use rights and restrictions.
13 | *
14 | * Copyright (C) 1999 - 2012 by ANHUI USTC iFLYTEK, Co,LTD.
15 | * All rights reserved.
16 | *
17 | * @author Speech Dept. iFLYTEK.
18 | * @version 1.0
19 | * @date 2012/4/16
20 | *
21 | * @see
22 | *
23 | * History:
24 | *
25 | * | Version | Date | Author | Notes |
26 | * | 1.0 | 2012/4/16 | MSP40 | Create this file |
27 | *
28 | *
29 | */
30 |
31 | #ifndef __MSP_ISE_H__
32 | #define __MSP_ISE_H__
33 |
34 | #ifdef __cplusplus
35 | extern "C" {
36 | #endif /* C++ */
37 |
38 | #include "msp_types.h"
39 |
40 | /**
41 | * @fn QISEInit
42 | * @brief Initialize API
43 | *
44 | * Load API module with specified configurations.
45 | *
46 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
47 | * @param const char* configs - [in] Configurations to initialize.
48 | * @see
49 | */
50 | /*int MSPAPI QISEInit(const char* configs);
51 | typedef int (MSPAPI *Proc_QISEInit)(const char* configs);
52 | #ifdef MSP_WCHAR_SUPPORT
53 | int MSPAPI QISEInitW(const wchar_t* configs);
54 | typedef int (MSPAPI *Proc_QISEInitW)(const wchar_t* configs);
55 | #endif*/
56 |
57 | /**
58 | * @fn QISESessionBegin
59 | * @brief Begin a Evaluation Session
60 | *
61 | * Create a evaluation session to evaluate audio data
62 | *
63 | * @return const char* MSPAPI - Return the new session id in success, otherwise return NULL.
64 | * @param const char* params - [in] Parameters to create session.
65 | * @param const char* userModelId - [in] user model id.
66 | * @param int *errorCode - [out] Return 0 in success, otherwise return error code.
67 | * @see
68 | */
69 | const char* MSPAPI QISESessionBegin(const char* params, const char* userModelId, int* errorCode);
70 | typedef const char* (MSPAPI *Proc_QISESessionBegin)(const char* params, const char* userModelID, int *errorCode);
71 | #ifdef MSP_WCHAR_SUPPORT
72 | const wchar_t* MSPAPI QISESessionBeginW(const wchar_t* params, const wchar_t* userModelID, int *errorCode);
73 | typedef const wchar_t* (MSPAPI *Proc_QISESessionBeginW)(const wchar_t* params, const wchar_t* userModelID, int *errorCode);
74 | #endif
75 |
76 | /**
77 | * @fn QISETextPut
78 | * @brief Put Text
79 | *
80 | * Writing text string to evaluator.
81 | *
82 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
83 | * @param const char* sessionID - [in] The session id returned by QISESessionBegin.
84 | * @param const char* textString - [in] Text buffer.
85 | * @param unsigned int textLen - [in] Text length in bytes.
86 | * @param const char* params - [in] Parameters describing the text.
87 | * @see
88 | */
89 | int MSPAPI QISETextPut(const char* sessionID, const char* textString, unsigned int textLen, const char* params);
90 | typedef int (MSPAPI *Proc_QISETextPut)(const char* sessionID, const char* textString, unsigned int textLen, const char* params);
91 | #ifdef MSP_WCHAR_SUPPORT
92 | int MSPAPI QISETextPutW(const wchar_t* sessionID, const wchar_t* textString, unsigned int textLen, const wchar_t* params);
93 | typedef int (MSPAPI *Proc_QISETextPutW)(const wchar_t* sessionID, const wchar_t* textString, unsigned int textLen, const wchar_t* params);
94 | #endif
95 |
96 | /**
97 | * @fn QISEAudioWrite
98 | * @brief Write Audio
99 | *
100 | * Writing binary audio data to evaluator.
101 | *
102 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
103 | * @param const char* sessionID - [in] The session id returned by QISESessionBegin.
104 | * @param const void* waveData - [in] Audio data to write.
105 | * @param unsigned int waveLen - [in] Audio length in bytes.
106 | * @param int audioStatus - [in] Audio status.
107 | * @param int *epStatus - [out] EP or vad status.
108 | * @param int *evlStatus - [out] Status of evaluation result, 0: success, 1: no match, 2: incomplete, 5:speech complete.
109 | * @see
110 | */
111 | int MSPAPI QISEAudioWrite(const char* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *Status);
112 | typedef int (MSPAPI *Proc_QISEAudioWrite)(const char* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
113 | #ifdef MSP_WCHAR_SUPPORT
114 | int MSPAPI QISEAudioWriteW(const wchar_t* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *evlStatus);
115 | typedef int (MSPAPI *Proc_QISEAudioWriteW)(const wchar_t* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *evlStatus);
116 | #endif
117 |
118 | /**
119 | * @fn QISEGetResult
120 | * @brief Get Evaluation Result
121 | *
122 | * Get evaluation result.
123 | *
124 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
125 | * @param const char* sessionID - [in] The session id returned by QISESessionBegin.
126 | * @param int* rsltLen - [out] Length of result returned.
127 | * @param int* rsltStatus - [out] Status of evaluation result returned.
128 | * @param int* errorCode - [out] Return 0 in success, otherwise return error code.
129 | * @see
130 | */
131 | const char * MSPAPI QISEGetResult(const char* sessionID, unsigned int* rsltLen, int* rsltStatus, int *errorCode);
132 | typedef const char * (MSPAPI *Proc_QISEGetResult)(const char* sessionID, unsigned int* rsltLen, int* rsltStatus, int *errorCode);
133 | #ifdef MSP_WCHAR_SUPPORT
134 | const wchar_t* MSPAPI QISEGetResultW(const wchar_t* sessionID, int* rsltLen, unsigned int* rsltStatus, int *errorCode);
135 | typedef const wchar_t* (MSPAPI *Proc_QISEGetResultW)(const wchar_t* sessionID, unsigned int* rsltLen, int* rsltStatus, int *errorCode);
136 | #endif
137 |
138 | /**
139 | * @fn QISEResultInfo
140 | * @brief Get Result Info
141 | *
142 | * Get info of evaluation result.
143 | *
144 | * @return const char * - The session id returned by QISESessionBegin.
145 | * @param const char* sessionID - [in] session id returned by QISESessionBegin.
146 | * @see
147 | */
148 | const char* MSPAPI QISEResultInfo(const char* sessionID, int *errorCode);
149 | typedef const char* (MSPAPI *Proc_QISEResultInfo)(const char* sessionID, int *errorCode);
150 | #ifdef MSP_WCHAR_SUPPORT
151 | const wchar_t* MSPAPI QISEResultInfoW(const wchar_t* sessionID, int *errorCode);
152 | typedef const wchar_t* (MSPAPI *Proc_QISEResultInfoW)(const wchar_t* sessionID, int *errorCode);
153 | #endif
154 |
155 | /**
156 | * @fn QISESessionEnd
157 | * @brief End a ISR Session
158 | *
159 | * End a evaluation session, release all resource.
160 | *
161 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
162 | * @param const char* sessionID - [in] The session id returned by QISESessionBegin.
163 | * @param const char* hints - [in] Reason to end current session.
164 | * @see
165 | */
166 | int MSPAPI QISESessionEnd(const char* sessionID, const char* hints);
167 | typedef int (MSPAPI *Proc_QISESessionEnd)(const char* sessionID, const char* hints);
168 | #ifdef MSP_WCHAR_SUPPORT
169 | int MSPAPI QISESessionEndW(const wchar_t* sessionID, const wchar_t* hints);
170 | typedef int (MSPAPI *Proc_QISESessionEndW)(const wchar_t* sessionID, const wchar_t* hints);
171 | #endif
172 |
173 | /**
174 | * @fn QISEGetParam
175 | * @brief get params related with msc
176 | *
177 | * the params could be local or server param, we only support netflow params "upflow" & "downflow" now
178 | *
179 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
180 | * @param const char* sessionID - [in] session id of related param, set NULL to got global param
181 | * @param const char* paramName - [in] param name,could pass more than one param splited by ',' ';' or '\n'.
182 | * @param const char* paramValue - [in] param value buffer, malloced by user.
183 | * @param int *valueLen - [in, out] in: length of value buffer, out: length of value string.
184 | * @see
185 | */
186 | int MSPAPI QISEGetParam(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
187 | typedef int (MSPAPI *Proc_QISEGetParam)(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
188 | #ifdef MSP_WCHAR_SUPPORT
189 | int MSPAPI QISEGetParamW(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue, unsigned int* valueLen);
190 | typedef int (MSPAPI *Proc_QISEGetParamW)(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue, unsigned int* valueLen);
191 | #endif
192 |
193 | /*
194 | //
195 | // typedef void ( MSPAPI *recog_result_ntf_handler)( const char *sessionID, const char *result, int resultLen, int resultStatus, void *userData );
196 | // typedef void ( MSPAPI *status_ntf_handler)( const char *sessionID, int type, int status, const void *param1, const void *param2, void *userData);
197 | // typedef void ( MSPAPI *error_ntf_handler)(const char *sessionID, int errorCode, const char *detail, void *userData);
198 | // int MSPAPI QISRRegisterNotify(const char *sessionID, recog_result_ntf_handler rsltCb, status_ntf_handler statusCb, error_ntf_handler errCb, void *userData);
199 | */
200 |
201 |
202 | #ifdef __cplusplus
203 | } /* extern "C" */
204 | #endif /* C++ */
205 |
206 | #endif /* __MSP_ISE_H__ */
207 |
--------------------------------------------------------------------------------
/src/qisr.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file qisr.h
3 | * @brief iFLY Speech Recognizer Header File
4 | *
5 | * This file contains the quick application programming interface (API) declarations
6 | * of ISR. Developer can include this file in your project to build applications.
7 | * For more information, please read the developer guide.
8 |
9 | * Use of this software is subject to certain restrictions and limitations set
10 | * forth in a license agreement entered into between iFLYTEK, Co,LTD.
11 | * and the licensee of this software. Please refer to the license
12 | * agreement for license use rights and restrictions.
13 | *
14 | * Copyright (C) 1999 - 2007 by ANHUI USTC iFLYTEK, Co,LTD.
15 | * All rights reserved.
16 | *
17 | * @author Speech Dept. iFLYTEK.
18 | * @version 1.0
19 | * @date 2008/12/12
20 | *
21 | * @see
22 | *
23 | * History:
24 | * index version date author notes
25 | * 0 1.0 2008/12/12 Speech Create this file
26 | */
27 |
28 | #ifndef __QISR_H__
29 | #define __QISR_H__
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif /* C++ */
34 |
35 | #include "msp_types.h"
36 |
37 | /**
38 | * @fn QISRSessionBegin
39 | * @brief Begin a Recognizer Session
40 | *
41 | * Create a recognizer session to recognize audio data
42 | *
43 | * @return return sessionID of current session, NULL is failed.
44 | * @param const char* grammarList - [in] grammars list, inline grammar support only one.
45 | * @param const char* params - [in] parameters when the session created.
46 | * @param int *errorCode - [out] return 0 on success, otherwise return error code.
47 | * @see
48 | */
49 | const char* MSPAPI QISRSessionBegin(const char* grammarList, const char* params, int* errorCode);
50 | typedef const char* (MSPAPI *Proc_QISRSessionBegin)(const char* grammarList, const char* params, int *result);
51 | #ifdef MSP_WCHAR_SUPPORT
52 | const wchar_t* MSPAPI QISRSessionBeginW(const wchar_t* grammarList, const wchar_t* params, int *result);
53 | typedef const wchar_t* (MSPAPI *Proc_QISRSessionBeginW)(const wchar_t* grammarList, const wchar_t* params, int *result);
54 | #endif
55 |
56 |
57 | /**
58 | * @fn QISRAudioWrite
59 | * @brief Write Audio Data to Recognizer Session
60 | *
61 | * Writing binary audio data to recognizer.
62 | *
63 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
64 | * @param const char* sessionID - [in] The session id returned by recog_begin
65 | * @param const void* waveData - [in] Binary data of waveform
66 | * @param unsigned int waveLen - [in] Waveform data size in bytes
67 | * @param int audioStatus - [in] Audio status, can be
68 | * @param int *epStatus - [out] ISRepState
69 | * @param int *recogStatus - [out] ISRrecRecognizerStatus, see isr_rec.h
70 | * @see
71 | */
72 | int MSPAPI QISRAudioWrite(const char* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
73 | typedef int (MSPAPI *Proc_QISRAudioWrite)(const char* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
74 | #ifdef MSP_WCHAR_SUPPORT
75 | int MSPAPI QISRAudioWriteW(const wchar_t* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
76 | typedef int (MSPAPI *Proc_QISRAudioWriteW)(const wchar_t* sessionID, const void* waveData, unsigned int waveLen, int audioStatus, int *epStatus, int *recogStatus);
77 | #endif
78 |
79 | /**
80 | * @fn QISRGetResult
81 | * @brief Get Recognize Result in Specified Format
82 | *
83 | * Get recognize result in Specified format.
84 | *
85 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
86 | * @param const char* sessionID - [in] session id returned by session begin
87 | * @param int* rsltStatus - [out] status of recognition result, 0: success, 1: no match, 2: incomplete, 5:speech complete
88 | * @param int *errorCode - [out] return 0 on success, otherwise return error code.
89 | * @see
90 | */
91 | const char * MSPAPI QISRGetResult(const char* sessionID, int* rsltStatus, int waitTime, int *errorCode);
92 | typedef const char * (MSPAPI *Proc_QISRGetResult)(const char* sessionID, int* rsltStatus, int waitTime, int *errorCode);
93 | #ifdef MSP_WCHAR_SUPPORT
94 | const wchar_t* MSPAPI QISRGetResultW(const wchar_t* sessionID, int* rsltStatus, int waitTime, int *errorCode);
95 | typedef const wchar_t* (MSPAPI *Proc_QISRGetResultW)(const wchar_t* sessionID, int* rsltStatus, int waitTime, int *errorCode);
96 | #endif
97 |
98 | /**
99 | * @fn QISRGetBinaryResult
100 | * @brief Get Recognize Result in Specified Format
101 | *
102 | * Get recognize result in Specified format.
103 | *
104 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
105 | * @param const char* sessionID - [in] session id returned by session begin
106 | * @param int* rsltStatus - [out] status of recognition result, 0: success, 1: no match, 2: incomplete, 5:speech complete
107 | * @param int *errorCode - [out] return 0 on success, otherwise return error code.
108 | * @see
109 | */
110 | const char * MSPAPI QISRGetBinaryResult(const char* sessionID, unsigned int* rsltLen,int* rsltStatus, int waitTime, int *errorCode);
111 | typedef const char * (MSPAPI *Proc_QISRGetBinaryResult)(const char* sessionID, unsigned int* rsltLen, int* rsltStatus, int waitTime, int *errorCode);
112 | #ifdef MSP_WCHAR_SUPPORT
113 | const wchar_t* MSPAPI QISRGetBinaryResultW(const wchar_t* sessionID, unsigned int* rsltLen, int* rsltStatus, int waitTime, int *errorCode);
114 | typedef const wchar_t* (MSPAPI *Proc_QISRGetBinaryResultW)(const wchar_t* sessionID, unsigned int* rsltLen, int* rsltStatus, int waitTime, int *errorCode);
115 | #endif
116 |
117 |
118 | /**
119 | * @fn QISRSessionEnd
120 | * @brief End a Recognizer Session
121 | *
122 | * End the recognizer session, release all resource.
123 | *
124 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
125 | * @param const char* sessionID - [in] session id string to end
126 | * @param const char* hints - [in] user hints to end session, hints will be logged to CallLog
127 | * @see
128 | */
129 | int MSPAPI QISRSessionEnd(const char* sessionID, const char* hints);
130 | typedef int (MSPAPI *Proc_QISRSessionEnd)(const char* sessionID, const char* hints);
131 | #ifdef MSP_WCHAR_SUPPORT
132 | int MSPAPI QISRSessionEndW(const wchar_t* sessionID, const wchar_t* hints);
133 | typedef int (MSPAPI *Proc_QISRSessionEndW)(const wchar_t* sessionID, const wchar_t* hints);
134 | #endif
135 |
136 | /**
137 | * @fn QISRGetParam
138 | * @brief get params related with msc
139 | *
140 | * the params could be local or server param, we only support netflow params "upflow" & "downflow" now
141 | *
142 | * @return int - Return 0 if success, otherwise return errcode.
143 | * @param const char* sessionID - [in] session id of related param, set NULL to got global param
144 | * @param const char* paramName - [in] param name,could pass more than one param split by ','';'or'\n'
145 | * @param const char* paramValue - [in] param value buffer, malloced by user
146 | * @param int *valueLen - [in, out] pass in length of value buffer, and return length of value string
147 | * @see
148 | */
149 | int MSPAPI QISRGetParam(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
150 | typedef int (MSPAPI *Proc_QISRGetParam)(const char* sessionID, const char* paramName, char* paramValue, unsigned int* valueLen);
151 | #ifdef MSP_WCHAR_SUPPORT
152 | int MSPAPI QISRGetParamW(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue, unsigned int* valueLen);
153 | typedef int (MSPAPI *Proc_QISRGetParamW)(const wchar_t* sessionID, const wchar_t* paramName, wchar_t* paramValue, unsigned int* valueLen);
154 | #endif
155 |
156 | /**
157 | * @fn QISRSetParam
158 | * @brief get params related with msc
159 | *
160 | * the params could be local or server param, we only support netflow params "upflow" & "downflow" now
161 | *
162 | * @return int - Return 0 if success, otherwise return errcode.
163 | * @param const char* sessionID - [in] session id of related param, set NULL to got global param
164 | * @param const char* paramName - [in] param name,could pass more than one param split by ','';'or'\n'
165 | * @param const char* paramValue - [in] param value buffer, malloced by user
166 | * @param int *valueLen - [in, out] pass in length of value buffer, and return length of value string
167 | * @see
168 | */
169 | int MSPAPI QISRSetParam(const char* sessionID, const char* paramName, const char* paramValue);
170 | typedef int (MSPAPI *Proc_QISRSetParam)(const char* sessionID, const char* paramName, const char* paramValue);
171 | #ifdef MSP_WCHAR_SUPPORT
172 | int MSPAPI QISRSetParamW(const wchar_t* sessionID, const wchar_t* paramName, const wchar_t* paramValue);
173 | typedef int (MSPAPI *Proc_QISRSetParamW)(const wchar_t* sessionID, const wchar_t* paramName, const wchar_t* paramValue);
174 | #endif
175 |
176 |
177 | typedef void ( *recog_result_ntf_handler)( const char *sessionID, const char *result, int resultLen, int resultStatus, void *userData );
178 | typedef void ( *recog_status_ntf_handler)( const char *sessionID, int type, int status, int param1, const void *param2, void *userData);
179 | typedef void ( *recog_error_ntf_handler)(const char *sessionID, int errorCode, const char *detail, void *userData);
180 | int MSPAPI QISRRegisterNotify(const char *sessionID, recog_result_ntf_handler rsltCb, recog_status_ntf_handler statusCb, recog_error_ntf_handler errCb, void *userData);
181 |
182 | typedef int ( *UserCallBack)( int, const char*, void*);
183 | typedef int ( *GrammarCallBack)( int, const char*, void*);
184 | typedef int ( *LexiconCallBack)( int, const char*, void*);
185 |
186 | int MSPAPI QISRBuildGrammar(const char *grammarType, const char *grammarContent, unsigned int grammarLength, const char *params, GrammarCallBack callback, void *userData);
187 | typedef int (MSPAPI *Proc_QISRBuildGrammar)(const char *grammarType, const char *grammarContent, unsigned int grammarLength, const char *params, GrammarCallBack callback, void *userData);
188 | #ifdef MSP_WCHAR_SUPPORT
189 | int MSPAPI QISRBuildGrammarW(const wchar_t *grmmarType, const wchar_t *grammarContent, unsigned int grammarLength, const wchar_t *params, GrammarCallBack callback, void *userData);
190 | typedef int (MSPAPI *Proc_QISRBuildGrammarW)(const wchar_t *grmmarType, const wchar_t *grammarContent, unsigned int grammarLength, const wchar_t *params, GrammarCallBack callback, void *userData);
191 | #endif
192 |
193 | int MSPAPI QISRUpdateLexicon(const char *lexiconName, const char *lexiconContent, unsigned int lexiconLength, const char *params, LexiconCallBack callback, void *userData);
194 | typedef int (MSPAPI *Proc_QISRUpdataLexicon)(const char *lexiconName, const char *lexiconContent, unsigned int lexiconLength, const char *params, LexiconCallBack callback, void *userData);
195 | #ifdef MSP_WCHAR_SUPPORT
196 | int MSPAPI QISRUpdateLexiconW(const wchar_t *lexiconName, const wchar_t *lexiconContent, unsigned int lexiconLength, const wchar_t *params, LexiconCallBack callback, void *userData);
197 | typedef int (MSPAPI Proc_QISRUpdateLexiconW)(const wchar_t *lexiconName, const wchar_t *lexiconContent, unsigned int lexiconLength, const wchar_t *params, LexiconCallBack callback, void *userData);
198 | #endif
199 | #ifdef __cplusplus
200 | } /* extern "C" */
201 | #endif /* C++ */
202 |
203 | #endif /* __QISR_H__ */
204 |
--------------------------------------------------------------------------------
/src/msp_cmn.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file msp_cmn.h
3 | * @brief Mobile Speech Platform Common Interface Header File
4 | *
5 | * This file contains the quick common programming interface (API) declarations
6 | * of MSP. Developer can include this file in your project to build applications.
7 | * For more information, please read the developer guide.
8 |
9 | * Use of this software is subject to certain restrictions and limitations set
10 | * forth in a license agreement entered into between iFLYTEK, Co,LTD.
11 | * and the licensee of this software. Please refer to the license
12 | * agreement for license use rights and restrictions.
13 | *
14 | * Copyright (C) 1999 - 2012 by ANHUI USTC iFLYTEK, Co,LTD.
15 | * All rights reserved.
16 | *
17 | * @author Speech Dept. iFLYTEK.
18 | * @version 1.0
19 | * @date 2012/09/01
20 | *
21 | * @see
22 | *
23 | * History:
24 | * index version date author notes
25 | * 0 1.0 2012/09/01 MSC40 Create this file
26 | */
27 |
28 | #ifndef __MSP_CMN_H__
29 | #define __MSP_CMN_H__
30 |
31 | #include "msp_types.h"
32 |
33 | #ifdef __cplusplus
34 | extern "C" {
35 | #endif /* C++ */
36 | //#ifdef MSP_WCHAR_SUPPORT
37 | /**
38 | * @fn Wchar2Mbytes
39 | * @brief wchar to mbytes
40 | *
41 | * User login.
42 | *
43 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
44 | * @param const wchar_t* wcstr - [in] Null-terminated source string(wchar_t *).
45 | * @param char* mbstr - [in] Destination string(char *).
46 | * @param int len - [in] The maximum number of bytes that can be stored in the multibyte output string.
47 | * @see
48 | */
49 |
50 | char *Wchar2Mbytes(const wchar_t* wcstr);
51 |
52 | /**
53 | * @fn Mbytes2Wchar
54 | * @brief mbytes to wchar
55 | *
56 | * User login.
57 | *
58 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
59 | * @param const char* mbstr - [in] Null-terminated source string(char *).
60 | * @param wchar_t* wcstr - [in] Destination string(wchar_t *).
61 | * @param int wlen - [in] The maximum number of multibyte characters to convert.
62 | * @see
63 | */
64 | wchar_t *Mbytes2Wchar(const char *mbstr);
65 |
66 | //#endif /*MSP_WCHAR_SUPPORT*/
67 |
68 | /**
69 | * @fn MSPLogin
70 | * @brief user login interface
71 | *
72 | * User login.
73 | *
74 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
75 | * @param const char* usr - [in] user name.
76 | * @param const char* pwd - [in] password.
77 | * @param const char* params - [in] parameters when user login.
78 | * @see
79 | */
80 | int MSPAPI MSPLogin(const char* usr, const char* pwd, const char* params);
81 | typedef int (MSPAPI *Proc_MSPLogin)(const char* usr, const char* pwd, const char* params);
82 | //#ifdef MSP_WCHAR_SUPPORT
83 | int MSPAPI MSPLoginW(const wchar_t* usr, const wchar_t* pwd, const wchar_t* params);
84 | typedef int (MSPAPI *Proc_MSPLoginW)(const wchar_t* usr, const wchar_t* pwd, const wchar_t* params);
85 | //#endif/*MSP_WCHAR_SUPPORT*/
86 | /**
87 | * @fn MSPLogout
88 | * @brief user logout interface
89 | *
90 | * User logout
91 | *
92 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
93 | * @see
94 | */
95 | int MSPAPI MSPLogout();
96 | typedef int (MSPAPI *Proc_MSPLogout)();
97 | //#ifdef MSP_WCHAR_SUPPORT
98 | int MSPAPI MSPLogoutW();
99 | typedef int (MSPAPI *Proc_MSPLogoutW)();
100 | //#endif/*MSP_WCHAR_SUPPORT*/
101 | /**
102 | * @fn MSPUpload
103 | * @brief Upload User Specific Data
104 | *
105 | * Upload data such as user config, custom grammar, etc.
106 | *
107 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
108 | * @param const char* dataName - [in] data name, should be unique to diff other data.
109 | * @param const char* params - [in] parameters about uploading data.
110 | * @param const char* dataID - [in] id of the data to be operated.
111 | * @see
112 | */
113 | int MSPAPI MSPUpload( const char* dataName, const char* params, const char* dataID);
114 | typedef int (MSPAPI* Proc_MSPUpload)( const char* dataName, const char* params, const char* dataID);
115 |
116 | /**
117 | * @fn MSPDownload
118 | * @brief Download User Specific Data
119 | *
120 | * Download data such as user config, etc.
121 | *
122 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
123 | * @param const char* params - [in] parameters about data to be downloaded.
124 | * @see
125 | */
126 | typedef int (*DownloadStatusCB)(int errorCode, long param1, const void *param2, void *userData);
127 | typedef int (*DownloadResultCB)(const void *data, long dataLen, void *userData);
128 | int MSPAPI MSPDownload(const char* dataName, const char* params, DownloadStatusCB statusCb, DownloadResultCB resultCb, void*userData);
129 | typedef int (MSPAPI* Proc_MSPDownload)(const char* dataName, const char* params, DownloadStatusCB statusCb, DownloadResultCB resultCb, void*userData);
130 | int MSPAPI MSPDownloadW(const wchar_t* wdataName, const wchar_t* wparams, DownloadStatusCB statusCb, DownloadResultCB resultCb, void*userData);
131 | typedef int (MSPAPI* Proc_MSPDownloadW) (const wchar_t* wdataName, const wchar_t* wparams, DownloadStatusCB statusCb, DownloadResultCB resultCb, void*userData);
132 |
133 | /**
134 | * @fn MSPAppendData
135 | * @brief Append Data.
136 | *
137 | * Write data to msc, such as data to be uploaded, searching text, etc.
138 | *
139 | * @return int MSPAPI - Return 0 in success, otherwise return error code.
140 | * @param void* data - [in] the data buffer pointer, data could be binary.
141 | * @param unsigned int dataLen - [in] length of data.
142 | * @param unsigned int dataStatus - [in] data status, 2: first or continuous, 4: last.
143 | * @see
144 | */
145 | int MSPAPI MSPAppendData(void* data, unsigned int dataLen, unsigned int dataStatus);
146 | typedef int (MSPAPI* Proc_MSPAppendData)(void* data, unsigned int dataLen, unsigned int dataStatus);
147 |
148 | /**
149 | * @fn MSPGetResult
150 | * @brief Get Result
151 | *
152 | * Get result of uploading, downloading or searching, etc.
153 | *
154 | * @return const char* MSPAPI - Return result of uploading, downloading or searching, etc.
155 | * @param int* rsltLen - [out] Length of result returned.
156 | * @param int* rsltStatus - [out] Status of result returned.
157 | * @param int* errorCode - [out] Return 0 in success, otherwise return error code.
158 | * @see
159 | */
160 | const char* MSPAPI MSPGetResult(unsigned int* rsltLen, int* rsltStatus, int *errorCode);
161 | typedef const char * (MSPAPI *Proc_MSPGetResult)(unsigned int* rsltLen, int* rsltStatus, int *errorCode);
162 |
163 | /**
164 | * @fn MSPSetParam
165 | * @brief set params of msc
166 | *
167 | * set param of msc
168 | *
169 | * @return int - Return 0 if success, otherwise return errcode.
170 | * @param const char* paramName - [in] param name.
171 | * @param const char* paramValue - [in] param value
172 | * @see
173 | */
174 | int MSPAPI MSPSetParam( const char* paramName, const char* paramValue );
175 | typedef int (MSPAPI *Proc_MSPSetParam)(const char* paramName, const char* paramValue);
176 |
177 | /**
178 | * @fn MSPGetParam
179 | * @brief get params of msc
180 | *
181 | * get param of msc
182 | *
183 | * @return int - Return 0 if success, otherwise return errcode.
184 | * @param const char* paramName - [in] param name.
185 | * @param const char* paramValue - [out] param value
186 | * @param const char* valueLen - [in/out] param value (buffer) length
187 | * @see
188 | */
189 | int MSPAPI MSPGetParam( const char *paramName, char *paramValue, unsigned int *valueLen );
190 | typedef int (MSPAPI *Proc_MSPGetParam)( const char *paramName, char *paramValue, unsigned int *valueLen );
191 |
192 | /**
193 | * @fn MSPUploadData
194 | * @brief Upload User Specific Data
195 | *
196 | * Upload data such as user config, custom grammar, etc.
197 | *
198 | * @return const char* MSPAPI - data id returned by Server, used for special command.
199 | * @param const char* dataName - [in] data name, should be unique to diff other data.
200 | * @param void* data - [in] the data buffer pointer, data could be binary.
201 | * @param unsigned int dataLen - [in] length of data.
202 | * @param const char* params - [in] parameters about uploading data.
203 | * @param int* errorCode - [out] Return 0 in success, otherwise return error code.
204 | * @see
205 | */
206 | const char* MSPAPI MSPUploadData(const char* dataName, void* data, unsigned int dataLen, const char* params, int* errorCode);
207 | typedef const char* (MSPAPI* Proc_MSPUploadData)(const char* dataName, void* data, unsigned int dataLen, const char* params, int* errorCode);
208 |
209 | /**
210 | * @fn MSPDownloadData
211 | * @brief Download User Specific Data
212 | *
213 | * Download data such as user config, etc.
214 | *
215 | * @return const void* MSPAPI - received data buffer pointer, data could be binary, NULL if failed or data does not exsit.
216 | * @param const char* params - [in] parameters about data to be downloaded.
217 | * @param unsigned int* dataLen - [out] length of received data.
218 | * @param int* errorCode - [out] Return 0 in success, otherwise return error code.
219 | * @see
220 | */
221 | const void* MSPAPI MSPDownloadData(const char* params, unsigned int* dataLen, int* errorCode);
222 | typedef const void* (MSPAPI* Proc_MSPDownloadData)(const char* params, unsigned int* dataLen, int* errorCode);
223 | //#ifdef MSP_WCHAR_SUPPORT
224 | const void* MSPAPI MSPDownloadDataW(const wchar_t* params, unsigned int* dataLen, int* errorCode);
225 | typedef const void* (MSPAPI* Proc_MSPDownloadDataW)(const wchar_t* params, unsigned int* dataLen, int* errorCode);
226 | //#endif/*MSP_WCHAR_SUPPORT*/
227 | /**
228 | * @fn MSPSearch
229 | * @brief Search text for result
230 | *
231 | * Search text content, and got text result
232 | *
233 | * @return const void* MSPAPI - received data buffer pointer, data could be binary, NULL if failed or data does not exsit.
234 | * @param const char* params - [in] parameters about data to be downloaded.
235 | * @param unsigned int* dataLen - [out] length of received data.
236 | * @param int* errorCode - [out] Return 0 in success, otherwise return error code.
237 | * @see
238 | */
239 | const char* MSPAPI MSPSearch(const char* params, const char* text, unsigned int* dataLen, int* errorCode);
240 | typedef const char* (MSPAPI* Proc_MSPSearch)(const char* params, const char* text, unsigned int* dataLen, int* errorCode);
241 |
242 |
243 |
244 | typedef int (*NLPSearchCB)(const char *sessionID, int errorCode, int status, const void* result, long rsltLen, void *userData);
245 | const char* MSPAPI MSPNlpSearch(const char* params, const char* text, unsigned int textLen, int *errorCode, NLPSearchCB callback, void *userData);
246 | typedef const char* (MSPAPI* Proc_MSPNlpSearch)(const char* params, const char* text, unsigned int textLen, int *errorCode, NLPSearchCB callback, void *userData);
247 | int MSPAPI MSPNlpSchCancel(const char *sessionID, const char *hints);
248 |
249 | /**
250 | * @fn MSPRegisterNotify
251 | * @brief Register a Callback
252 | *
253 | * Register a Callback
254 | *
255 | * @return int -
256 | * @param msp_status_ntf_handler statusCb - [in] notify handler
257 | * @param void *userData - [in] userData
258 | * @see
259 | */
260 | typedef void ( *msp_status_ntf_handler)( int type, int status, int param1, const void *param2, void *userData );
261 | int MSPAPI MSPRegisterNotify( msp_status_ntf_handler statusCb, void *userData );
262 | typedef const char* (MSPAPI* Proc_MSPRegisterNotify)( msp_status_ntf_handler statusCb, void *userData );
263 |
264 | /**
265 | * @fn MSPGetVersion
266 | * @brief Get version of MSC or Local Engine
267 | *
268 | * Get version of MSC or Local Engine
269 | *
270 | * @return const char * MSPAPI - Return version value if success, NULL if fail.
271 | * @param const char *verName - [in] version name, could be "msc", "aitalk", "aisound", "ivw".
272 | * @param int *errorCode - [out] Return 0 in success, otherwise return error code.
273 | * @see
274 | */
275 | const char* MSPAPI MSPGetVersion(const char *verName, int *errorCode);
276 | typedef const char* (MSPAPI * Proc_MSPGetVersion)(const char *verName, int *errorCode);
277 |
278 | #ifdef __cplusplus
279 | } /* extern "C" */
280 | #endif /* C++ */
281 |
282 | #endif /* __MSP_CMN_H__ */
283 |
--------------------------------------------------------------------------------
/src/linuxrec.c:
--------------------------------------------------------------------------------
1 | /*
2 | @file
3 | @brief record demo for linux
4 |
5 | @author taozhang9
6 | @date 2016/05/27
7 | */
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include "formats.h"
17 | #include "linuxrec.h"
18 |
19 | #define DBG_ON 1
20 |
21 | #if DBG_ON
22 | #define dbg printf
23 | #else
24 | #define dbg
25 | #endif
26 |
27 |
28 | /* Do not change the sequence */
29 | enum {
30 | RECORD_STATE_CREATED, /* Init */
31 | RECORD_STATE_CLOSING,
32 | RECORD_STATE_READY, /* Opened */
33 | RECORD_STATE_STOPPING, /* During Stop */
34 | RECORD_STATE_RECORDING, /* Started */
35 | };
36 |
37 | #define SAMPLE_RATE 16000
38 | #define SAMPLE_BIT_SIZE 16
39 | #define FRAME_CNT 10
40 | //#define BUF_COUNT 1
41 | #define DEF_BUFF_TIME 500000
42 | #define DEF_PERIOD_TIME 100000
43 |
44 | #define DEFAULT_FORMAT \
45 | {\
46 | WAVE_FORMAT_PCM, \
47 | 1, \
48 | 16000, \
49 | 32000, \
50 | 2, \
51 | 16, \
52 | sizeof(WAVEFORMATEX) \
53 | }
54 | #if 0
55 | struct bufinfo {
56 | char *data;
57 | unsigned int bufsize;
58 | };
59 | #endif
60 |
61 |
62 | static int show_xrun = 1;
63 | static int start_record_internal(snd_pcm_t *pcm)
64 | {
65 | return snd_pcm_start(pcm);
66 | }
67 |
68 | static int stop_record_internal(snd_pcm_t *pcm)
69 | {
70 | return snd_pcm_drop(pcm);
71 | }
72 |
73 |
74 | static int is_stopped_internal(struct recorder *rec)
75 | {
76 | snd_pcm_state_t state;
77 |
78 | state = snd_pcm_state((snd_pcm_t *)rec->wavein_hdl);
79 | switch (state) {
80 | case SND_PCM_STATE_RUNNING:
81 | case SND_PCM_STATE_DRAINING:
82 | return 0;
83 | default: break;
84 | }
85 | return 1;
86 |
87 | }
88 |
89 | static int format_ms_to_alsa(const WAVEFORMATEX * wavfmt,
90 | snd_pcm_format_t * format)
91 | {
92 | snd_pcm_format_t tmp;
93 | tmp = snd_pcm_build_linear_format(wavfmt->wBitsPerSample,
94 | wavfmt->wBitsPerSample, wavfmt->wBitsPerSample == 8 ? 1 : 0, 0);
95 | if ( tmp == SND_PCM_FORMAT_UNKNOWN )
96 | return -EINVAL;
97 | *format = tmp;
98 | return 0;
99 | }
100 |
101 | /* set hardware and software params */
102 | static int set_hwparams(struct recorder * rec, const WAVEFORMATEX *wavfmt,
103 | unsigned int buffertime, unsigned int periodtime)
104 | {
105 | snd_pcm_hw_params_t *params;
106 | int err;
107 | unsigned int rate;
108 | snd_pcm_format_t format;
109 | snd_pcm_uframes_t size;
110 | snd_pcm_t *handle = (snd_pcm_t *)rec->wavein_hdl;
111 |
112 | rec->buffer_time = buffertime;
113 | rec->period_time = periodtime;
114 |
115 | snd_pcm_hw_params_alloca(¶ms);
116 | err = snd_pcm_hw_params_any(handle, params);
117 | if (err < 0) {
118 | dbg("Broken configuration for this PCM");
119 | return err;
120 | }
121 | err = snd_pcm_hw_params_set_access(handle, params,
122 | SND_PCM_ACCESS_RW_INTERLEAVED);
123 | if (err < 0) {
124 | dbg("Access type not available");
125 | return err;
126 | }
127 | err = format_ms_to_alsa(wavfmt, &format);
128 | if (err) {
129 | dbg("Invalid format");
130 | return - EINVAL;
131 | }
132 | err = snd_pcm_hw_params_set_format(handle, params, format);
133 | if (err < 0) {
134 | dbg("Sample format non available");
135 | return err;
136 | }
137 | err = snd_pcm_hw_params_set_channels(handle, params, wavfmt->nChannels);
138 | if (err < 0) {
139 | dbg("Channels count non available");
140 | return err;
141 | }
142 |
143 | rate = wavfmt->nSamplesPerSec;
144 | err = snd_pcm_hw_params_set_rate_near(handle, params, &rate, 0);
145 | if (err < 0) {
146 | dbg("Set rate failed");
147 | return err;
148 | }
149 | if(rate != wavfmt->nSamplesPerSec) {
150 | dbg("Rate mismatch");
151 | return -EINVAL;
152 | }
153 | if (rec->buffer_time == 0 || rec->period_time == 0) {
154 | err = snd_pcm_hw_params_get_buffer_time_max(params,
155 | &rec->buffer_time, 0);
156 | assert(err >= 0);
157 | if (rec->buffer_time > 500000)
158 | rec->buffer_time = 500000;
159 | rec->period_time = rec->buffer_time / 4;
160 | }
161 | err = snd_pcm_hw_params_set_period_time_near(handle, params,
162 | &rec->period_time, 0);
163 | if (err < 0) {
164 | dbg("set period time fail");
165 | return err;
166 | }
167 | err = snd_pcm_hw_params_set_buffer_time_near(handle, params,
168 | &rec->buffer_time, 0);
169 | if (err < 0) {
170 | dbg("set buffer time failed");
171 | return err;
172 | }
173 | err = snd_pcm_hw_params_get_period_size(params, &size, 0);
174 | if (err < 0) {
175 | dbg("get period size fail");
176 | return err;
177 | }
178 | rec->period_frames = size;
179 | err = snd_pcm_hw_params_get_buffer_size(params, &size);
180 | if (size == rec->period_frames) {
181 | dbg("Can't use period equal to buffer size (%lu == %lu)",
182 | size, rec->period_frames);
183 | return -EINVAL;
184 | }
185 | rec->buffer_frames = size;
186 | rec->bits_per_frame = wavfmt->wBitsPerSample;
187 |
188 | /* set to driver */
189 | err = snd_pcm_hw_params(handle, params);
190 | if (err < 0) {
191 | dbg("Unable to install hw params:");
192 | return err;
193 | }
194 | return 0;
195 | }
196 | static int set_swparams(struct recorder * rec)
197 | {
198 | int err;
199 | snd_pcm_sw_params_t *swparams;
200 | snd_pcm_t * handle = (snd_pcm_t*)(rec->wavein_hdl);
201 | /* sw para */
202 | snd_pcm_sw_params_alloca(&swparams);
203 | err = snd_pcm_sw_params_current(handle, swparams);
204 | if (err < 0) {
205 | dbg("get current sw para fail");
206 | return err;
207 | }
208 |
209 | err = snd_pcm_sw_params_set_avail_min(handle, swparams,
210 | rec->period_frames);
211 | if (err < 0) {
212 | dbg("set avail min failed");
213 | return err;
214 | }
215 | /* set a value bigger than the buffer frames to prevent the auto start.
216 | * we use the snd_pcm_start to explicit start the pcm */
217 | err = snd_pcm_sw_params_set_start_threshold(handle, swparams,
218 | rec->buffer_frames * 2);
219 | if (err < 0) {
220 | dbg("set start threshold fail");
221 | return err;
222 | }
223 |
224 | if ( (err = snd_pcm_sw_params(handle, swparams)) < 0) {
225 | dbg("unable to install sw params:");
226 | return err;
227 | }
228 | return 0;
229 | }
230 |
231 | static int set_params(struct recorder *rec, WAVEFORMATEX *fmt,
232 | unsigned int buffertime, unsigned int periodtime)
233 | {
234 | int err;
235 | WAVEFORMATEX defmt = DEFAULT_FORMAT;
236 |
237 | if (fmt == NULL) {
238 | fmt = &defmt;
239 | }
240 | err = set_hwparams(rec, fmt, buffertime, periodtime);
241 | if (err)
242 | return err;
243 | err = set_swparams(rec);
244 | if (err)
245 | return err;
246 | return 0;
247 | }
248 |
249 | /*
250 | * Underrun and suspend recovery
251 | */
252 |
253 | static int xrun_recovery(snd_pcm_t *handle, int err)
254 | {
255 | if (err == -EPIPE) { /* over-run */
256 | if (show_xrun)
257 | printf("!!!!!!overrun happend!!!!!!");
258 |
259 | err = snd_pcm_prepare(handle);
260 | if (err < 0) {
261 | if (show_xrun)
262 | printf("Can't recovery from overrun,"
263 | "prepare failed: %s\n", snd_strerror(err));
264 | return err;
265 | }
266 | return 0;
267 | } else if (err == -ESTRPIPE) {
268 | while ((err = snd_pcm_resume(handle)) == -EAGAIN)
269 | usleep(200000); /* wait until the suspend flag is released */
270 | if (err < 0) {
271 | err = snd_pcm_prepare(handle);
272 | if (err < 0) {
273 | if (show_xrun)
274 | printf("Can't recovery from suspend,"
275 | "prepare failed: %s\n", snd_strerror(err));
276 | return err;
277 | }
278 | }
279 | return 0;
280 | }
281 | return err;
282 | }
283 | static ssize_t pcm_read(struct recorder *rec, size_t rcount)
284 | {
285 | ssize_t r;
286 | size_t count = rcount;
287 | char *data;
288 | snd_pcm_t *handle = (snd_pcm_t *)rec->wavein_hdl;
289 | if(!handle)
290 | return -EINVAL;
291 |
292 | data = rec->audiobuf;
293 | while (count > 0) {
294 | r = snd_pcm_readi(handle, data, count);
295 | if (r == -EAGAIN || (r >= 0 && (size_t)r < count)) {
296 | snd_pcm_wait(handle, 100);
297 | } else if (r < 0) {
298 | if(xrun_recovery(handle, r) < 0) {
299 | return -1;
300 | }
301 | }
302 |
303 | if (r > 0) {
304 | count -= r;
305 | data += r * rec->bits_per_frame / 8;
306 | }
307 | }
308 | return rcount;
309 | }
310 |
311 | static void * record_thread_proc(void * para)
312 | {
313 | struct recorder * rec = (struct recorder *) para;
314 | size_t frames, bytes;
315 | sigset_t mask, oldmask;
316 |
317 |
318 | sigemptyset(&mask);
319 | sigaddset(&mask, SIGINT);
320 | sigaddset(&mask, SIGTERM);
321 | pthread_sigmask(SIG_BLOCK, &mask, &oldmask);
322 |
323 | while(1) {
324 | frames = rec->period_frames;
325 | bytes = frames * rec->bits_per_frame / 8;
326 |
327 | /* closing, exit the thread */
328 | if (rec->state == RECORD_STATE_CLOSING)
329 | break;
330 |
331 | if(rec->state < RECORD_STATE_RECORDING)
332 | usleep(100000);
333 |
334 | if (pcm_read(rec, frames) != frames) {
335 | return NULL;
336 | }
337 |
338 | if (rec->on_data_ind)
339 | rec->on_data_ind(rec->audiobuf, bytes,
340 | rec->user_cb_para);
341 | }
342 | return rec;
343 |
344 | }
345 | static int create_record_thread(void * para, pthread_t * tidp)
346 | {
347 | int err;
348 | err = pthread_create(tidp, NULL, record_thread_proc, (void *)para);
349 | if (err != 0)
350 | return err;
351 |
352 | return 0;
353 | }
354 |
355 | #if 0 /* don't use it now... cuz only one buffer supported */
356 | static void free_rec_buffer(struct recorder * rec)
357 | {
358 | if (rec->bufheader) {
359 | unsigned int i;
360 | struct bufinfo *info = (struct bufinfo *) rec->bufheader;
361 |
362 | assert(rec->bufcount > 0);
363 | for (i = 0; i < rec->bufcount; ++i) {
364 | if (info->data) {
365 | free(info->data);
366 | info->data = NULL;
367 | info->bufsize = 0;
368 | info->audio_bytes = 0;
369 | }
370 | info++;
371 | }
372 | free(rec->bufheader);
373 | rec->bufheader = NULL;
374 | }
375 | rec->bufcount = 0;
376 | }
377 |
378 | static int prepare_rec_buffer(struct recorder * rec )
379 | {
380 | struct bufinfo *buffers;
381 | unsigned int i;
382 | int err;
383 | size_t sz;
384 |
385 | /* the read and QISRWrite is blocked, currently only support one buffer,
386 | * if overrun too much, need more buffer and another new thread
387 | * to write the audio to network */
388 | rec->bufcount = 1;
389 | sz = sizeof(struct bufinfo)*rec->bufcount;
390 | buffers=(struct bufinfo*)malloc(sz);
391 | if (!buffers) {
392 | rec->bufcount = 0;
393 | goto fail;
394 | }
395 | memset(buffers, 0, sz);
396 | rec->bufheader = buffers;
397 |
398 | for (i = 0; i < rec->bufcount; ++i) {
399 | buffers[i].bufsize =
400 | (rec->period_frames * rec->bits_per_frame / 8);
401 | buffers[i].data = (char *)malloc(buffers[i].bufsize);
402 | if (!buffers[i].data) {
403 | buffers[i].bufsize = 0;
404 | goto fail;
405 | }
406 | buffers[i].audio_bytes = 0;
407 | }
408 | return 0;
409 | fail:
410 | free_rec_buffer(rec);
411 | return -ENOMEM;
412 | }
413 | #else
414 | static void free_rec_buffer(struct recorder * rec)
415 | {
416 | if (rec->audiobuf) {
417 | free(rec->audiobuf);
418 | rec->audiobuf = NULL;
419 | }
420 | }
421 |
422 | static int prepare_rec_buffer(struct recorder * rec )
423 | {
424 | /* the read and QISRWrite is blocked, currently only support one buffer,
425 | * if overrun too much, need more buffer and another new thread
426 | * to write the audio to network */
427 | size_t sz = (rec->period_frames * rec->bits_per_frame / 8);
428 | rec->audiobuf = (char *)malloc(sz);
429 | if(!rec->audiobuf)
430 | return -ENOMEM;
431 | return 0;
432 | }
433 | #endif
434 |
435 | static int open_recorder_internal(struct recorder * rec,
436 | record_dev_id dev, WAVEFORMATEX * fmt)
437 | {
438 | int err = 0;
439 |
440 | err = snd_pcm_open((snd_pcm_t **)&rec->wavein_hdl, dev.u.name,
441 | SND_PCM_STREAM_CAPTURE, 0);
442 | if(err < 0)
443 | goto fail;
444 |
445 | err = set_params(rec, fmt, DEF_BUFF_TIME, DEF_PERIOD_TIME);
446 | if(err)
447 | goto fail;
448 |
449 | assert(rec->bufheader == NULL);
450 | err = prepare_rec_buffer(rec);
451 | if(err)
452 | goto fail;
453 |
454 | err = create_record_thread((void*)rec,
455 | &rec->rec_thread);
456 | if(err)
457 | goto fail;
458 |
459 |
460 | return 0;
461 | fail:
462 | if(rec->wavein_hdl)
463 | snd_pcm_close((snd_pcm_t *) rec->wavein_hdl);
464 | rec->wavein_hdl = NULL;
465 | free_rec_buffer(rec);
466 | return err;
467 | }
468 |
469 | static void close_recorder_internal(struct recorder *rec)
470 | {
471 | snd_pcm_t * handle;
472 |
473 | handle = (snd_pcm_t *) rec->wavein_hdl;
474 |
475 | /* may be the thread is blocked at read, cancel it */
476 | pthread_cancel(rec->rec_thread);
477 |
478 | /* wait for the pcm thread quit first */
479 | pthread_join(rec->rec_thread, NULL);
480 |
481 | if(handle) {
482 | snd_pcm_close(handle);
483 | rec->wavein_hdl = NULL;
484 | }
485 | free_rec_buffer(rec);
486 | }
487 | /* return the count of pcm device */
488 | /* list all cards */
489 | static int get_pcm_device_cnt(snd_pcm_stream_t stream)
490 | {
491 | void **hints, **n;
492 | char *io, *filter, *name;
493 | int cnt = 0;
494 |
495 | if (snd_device_name_hint(-1, "pcm", &hints) < 0)
496 | return 0;
497 | n = hints;
498 | filter = stream == SND_PCM_STREAM_CAPTURE ? "Input" : "Output";
499 | while (*n != NULL) {
500 | io = snd_device_name_get_hint(*n, "IOID");
501 | name = snd_device_name_get_hint(*n, "NAME");
502 | if (name && (io == NULL || strcmp(io, filter) == 0))
503 | cnt ++;
504 | if (io != NULL)
505 | free(io);
506 | if (name != NULL)
507 | free(name);
508 | n++;
509 | }
510 | snd_device_name_free_hint(hints);
511 | return cnt;
512 | }
513 |
514 | static void free_name_desc(char **name_or_desc)
515 | {
516 | char **ss;
517 | ss = name_or_desc;
518 | if(NULL == name_or_desc)
519 | return;
520 | while(*name_or_desc) {
521 | free(*name_or_desc);
522 | *name_or_desc = NULL;
523 | name_or_desc++;
524 | }
525 | free(ss);
526 | }
527 | /* return success: total count, need free the name and desc buffer
528 | * fail: -1 , *name_out and *desc_out will be NULL */
529 | static int list_pcm(snd_pcm_stream_t stream, char**name_out,
530 | char ** desc_out)
531 | {
532 | void **hints, **n;
533 | char **name, **descr;
534 | char *io;
535 | const char *filter;
536 | int cnt = 0;
537 | int i = 0;
538 |
539 | if (snd_device_name_hint(-1, "pcm", &hints) < 0)
540 | return 0;
541 | n = hints;
542 | cnt = get_pcm_device_cnt(stream);
543 | if(!cnt) {
544 | goto fail;
545 | }
546 |
547 | *name_out = calloc(sizeof(char *) , (1+cnt));
548 | if (*name_out == NULL)
549 | goto fail;
550 | *desc_out = calloc(sizeof(char *) , (1 + cnt));
551 | if (*desc_out == NULL)
552 | goto fail;
553 |
554 | /* the last one is a flag, NULL */
555 | name_out[cnt] = NULL;
556 | desc_out[cnt] = NULL;
557 | name = name_out;
558 | descr = desc_out;
559 |
560 | filter = stream == SND_PCM_STREAM_CAPTURE ? "Input" : "Output";
561 | while (*n != NULL && i < cnt) {
562 | *name = snd_device_name_get_hint(*n, "NAME");
563 | *descr = snd_device_name_get_hint(*n, "DESC");
564 | io = snd_device_name_get_hint(*n, "IOID");
565 | if (name == NULL ||
566 | (io != NULL && strcmp(io, filter) != 0) ){
567 | if (*name) free(*name);
568 | if (*descr) free(*descr);
569 | } else {
570 | if (*descr == NULL) {
571 | *descr = malloc(4);
572 | memset(*descr, 0, 4);
573 | }
574 | name++;
575 | descr++;
576 | i++;
577 | }
578 | if (io != NULL)
579 | free(io);
580 | n++;
581 | }
582 | snd_device_name_free_hint(hints);
583 | return cnt;
584 | fail:
585 | free_name_desc(name_out);
586 | free_name_desc(desc_out);
587 | snd_device_name_free_hint(hints);
588 | return -1;
589 | }
590 | /* -------------------------------------
591 | * Interfaces
592 | --------------------------------------*/
593 | /* the device id is a pcm string name in linux */
594 | record_dev_id get_default_input_dev()
595 | {
596 | record_dev_id id;
597 | id.u.name = "default";
598 | return id;
599 | }
600 |
601 | record_dev_id * list_input_device()
602 | {
603 | // TODO: unimplemented
604 | return NULL;
605 | }
606 |
607 | int get_input_dev_num()
608 | {
609 | return get_pcm_device_cnt(SND_PCM_STREAM_CAPTURE);
610 | }
611 |
612 |
613 | /* callback will be run on a new thread */
614 | int create_recorder(struct recorder ** out_rec,
615 | void (*on_data_ind)(char *data, unsigned long len, void *user_cb_para),
616 | void* user_cb_para)
617 | {
618 | struct recorder * myrec;
619 | myrec = (struct recorder *)malloc(sizeof(struct recorder));
620 | if(!myrec)
621 | return -RECORD_ERR_MEMFAIL;
622 |
623 | memset(myrec, 0, sizeof(struct recorder));
624 | myrec->on_data_ind = on_data_ind;
625 | myrec->user_cb_para = user_cb_para;
626 | myrec->state = RECORD_STATE_CREATED;
627 |
628 | *out_rec = myrec;
629 | return 0;
630 | }
631 |
632 | void destroy_recorder(struct recorder *rec)
633 | {
634 | if(!rec)
635 | return;
636 |
637 | free(rec);
638 | }
639 |
640 | int open_recorder(struct recorder * rec, record_dev_id dev, WAVEFORMATEX * fmt)
641 | {
642 | int ret = 0;
643 | if(!rec )
644 | return -RECORD_ERR_INVAL;
645 | if(rec->state >= RECORD_STATE_READY)
646 | return 0;
647 |
648 | ret = open_recorder_internal(rec, dev, fmt);
649 | if(ret == 0)
650 | rec->state = RECORD_STATE_READY;
651 | return 0;
652 |
653 | }
654 |
655 | void close_recorder(struct recorder *rec)
656 | {
657 | if(rec == NULL || rec->state < RECORD_STATE_READY)
658 | return;
659 | if(rec->state == RECORD_STATE_RECORDING)
660 | stop_record(rec);
661 |
662 | rec->state = RECORD_STATE_CLOSING;
663 |
664 | close_recorder_internal(rec);
665 |
666 | rec->state = RECORD_STATE_CREATED;
667 | }
668 |
669 | int start_record(struct recorder * rec)
670 | {
671 | int ret;
672 | if(rec == NULL)
673 | return -RECORD_ERR_INVAL;
674 | if( rec->state < RECORD_STATE_READY)
675 | return -RECORD_ERR_NOT_READY;
676 | if( rec->state == RECORD_STATE_RECORDING)
677 | return 0;
678 |
679 | ret = start_record_internal((snd_pcm_t *)rec->wavein_hdl);
680 | if(ret == 0)
681 | rec->state = RECORD_STATE_RECORDING;
682 | return ret;
683 | }
684 |
685 | int stop_record(struct recorder * rec)
686 | {
687 | int ret;
688 | if(rec == NULL)
689 | return -RECORD_ERR_INVAL;
690 | if( rec->state < RECORD_STATE_RECORDING)
691 | return 0;
692 |
693 | rec->state = RECORD_STATE_STOPPING;
694 | ret = stop_record_internal((snd_pcm_t *)rec->wavein_hdl);
695 | if(ret == 0) {
696 | rec->state = RECORD_STATE_READY;
697 | }
698 | return ret;
699 | }
700 |
701 | int is_record_stopped(struct recorder *rec)
702 | {
703 | if(rec->state == RECORD_STATE_RECORDING)
704 | return 0;
705 |
706 | return is_stopped_internal(rec);
707 | }
708 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 |
2 | GNU GENERAL PUBLIC LICENSE
3 | Version 3, 29 June 2007
4 |
5 | Copyright (C) 2007 Free Software Foundation, Inc.
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The GNU General Public License is a free, copyleft license for
12 | software and other kinds of works.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | the GNU General Public License is intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users. We, the Free Software Foundation, use the
19 | GNU General Public License for most of our software; it applies also to
20 | any other work released this way by its authors. You can apply it to
21 | your programs, too.
22 |
23 | When we speak of free software, we are referring to freedom, not
24 | price. Our General Public Licenses are designed to make sure that you
25 | have the freedom to distribute copies of free software (and charge for
26 | them if you wish), that you receive source code or can get it if you
27 | want it, that you can change the software or use pieces of it in new
28 | free programs, and that you know you can do these things.
29 |
30 | To protect your rights, we need to prevent others from denying you
31 | these rights or asking you to surrender the rights. Therefore, you have
32 | certain responsibilities if you distribute copies of the software, or if
33 | you modify it: responsibilities to respect the freedom of others.
34 |
35 | For example, if you distribute copies of such a program, whether
36 | gratis or for a fee, you must pass on to the recipients the same
37 | freedoms that you received. You must make sure that they, too, receive
38 | or can get the source code. And you must show them these terms so they
39 | know their rights.
40 |
41 | Developers that use the GNU GPL protect your rights with two steps:
42 | (1) assert copyright on the software, and (2) offer you this License
43 | giving you legal permission to copy, distribute and/or modify it.
44 |
45 | For the developers' and authors' protection, the GPL clearly explains
46 | that there is no warranty for this free software. For both users' and
47 | authors' sake, the GPL requires that modified versions be marked as
48 | changed, so that their problems will not be attributed erroneously to
49 | authors of previous versions.
50 |
51 | Some devices are designed to deny users access to install or run
52 | modified versions of the software inside them, although the manufacturer
53 | can do so. This is fundamentally incompatible with the aim of
54 | protecting users' freedom to change the software. The systematic
55 | pattern of such abuse occurs in the area of products for individuals to
56 | use, which is precisely where it is most unacceptable. Therefore, we
57 | have designed this version of the GPL to prohibit the practice for those
58 | products. If such problems arise substantially in other domains, we
59 | stand ready to extend this provision to those domains in future versions
60 | of the GPL, as needed to protect the freedom of users.
61 |
62 | Finally, every program is threatened constantly by software patents.
63 | States should not allow patents to restrict development and use of
64 | software on general-purpose computers, but in those that do, we wish to
65 | avoid the special danger that patents applied to a free program could
66 | make it effectively proprietary. To prevent this, the GPL assures that
67 | patents cannot be used to render the program non-free.
68 |
69 | The precise terms and conditions for copying, distribution and
70 | modification follow.
71 |
72 | TERMS AND CONDITIONS
73 |
74 | 0. Definitions.
75 |
76 | "This License" refers to version 3 of the GNU General Public License.
77 |
78 | "Copyright" also means copyright-like laws that apply to other kinds of
79 | works, such as semiconductor masks.
80 |
81 | "The Program" refers to any copyrightable work licensed under this
82 | License. Each licensee is addressed as "you". "Licensees" and
83 | "recipients" may be individuals or organizations.
84 |
85 | To "modify" a work means to copy from or adapt all or part of the work
86 | in a fashion requiring copyright permission, other than the making of an
87 | exact copy. The resulting work is called a "modified version" of the
88 | earlier work or a work "based on" the earlier work.
89 |
90 | A "covered work" means either the unmodified Program or a work based
91 | on the Program.
92 |
93 | To "propagate" a work means to do anything with it that, without
94 | permission, would make you directly or secondarily liable for
95 | infringement under applicable copyright law, except executing it on a
96 | computer or modifying a private copy. Propagation includes copying,
97 | distribution (with or without modification), making available to the
98 | public, and in some countries other activities as well.
99 |
100 | To "convey" a work means any kind of propagation that enables other
101 | parties to make or receive copies. Mere interaction with a user through
102 | a computer network, with no transfer of a copy, is not conveying.
103 |
104 | An interactive user interface displays "Appropriate Legal Notices"
105 | to the extent that it includes a convenient and prominently visible
106 | feature that (1) displays an appropriate copyright notice, and (2)
107 | tells the user that there is no warranty for the work (except to the
108 | extent that warranties are provided), that licensees may convey the
109 | work under this License, and how to view a copy of this License. If
110 | the interface presents a list of user commands or options, such as a
111 | menu, a prominent item in the list meets this criterion.
112 |
113 | 1. Source Code.
114 |
115 | The "source code" for a work means the preferred form of the work
116 | for making modifications to it. "Object code" means any non-source
117 | form of a work.
118 |
119 | A "Standard Interface" means an interface that either is an official
120 | standard defined by a recognized standards body, or, in the case of
121 | interfaces specified for a particular programming language, one that
122 | is widely used among developers working in that language.
123 |
124 | The "System Libraries" of an executable work include anything, other
125 | than the work as a whole, that (a) is included in the normal form of
126 | packaging a Major Component, but which is not part of that Major
127 | Component, and (b) serves only to enable use of the work with that
128 | Major Component, or to implement a Standard Interface for which an
129 | implementation is available to the public in source code form. A
130 | "Major Component", in this context, means a major essential component
131 | (kernel, window system, and so on) of the specific operating system
132 | (if any) on which the executable work runs, or a compiler used to
133 | produce the work, or an object code interpreter used to run it.
134 |
135 | The "Corresponding Source" for a work in object code form means all
136 | the source code needed to generate, install, and (for an executable
137 | work) run the object code and to modify the work, including scripts to
138 | control those activities. However, it does not include the work's
139 | System Libraries, or general-purpose tools or generally available free
140 | programs which are used unmodified in performing those activities but
141 | which are not part of the work. For example, Corresponding Source
142 | includes interface definition files associated with source files for
143 | the work, and the source code for shared libraries and dynamically
144 | linked subprograms that the work is specifically designed to require,
145 | such as by intimate data communication or control flow between those
146 | subprograms and other parts of the work.
147 |
148 | The Corresponding Source need not include anything that users
149 | can regenerate automatically from other parts of the Corresponding
150 | Source.
151 |
152 | The Corresponding Source for a work in source code form is that
153 | same work.
154 |
155 | 2. Basic Permissions.
156 |
157 | All rights granted under this License are granted for the term of
158 | copyright on the Program, and are irrevocable provided the stated
159 | conditions are met. This License explicitly affirms your unlimited
160 | permission to run the unmodified Program. The output from running a
161 | covered work is covered by this License only if the output, given its
162 | content, constitutes a covered work. This License acknowledges your
163 | rights of fair use or other equivalent, as provided by copyright law.
164 |
165 | You may make, run and propagate covered works that you do not
166 | convey, without conditions so long as your license otherwise remains
167 | in force. You may convey covered works to others for the sole purpose
168 | of having them make modifications exclusively for you, or provide you
169 | with facilities for running those works, provided that you comply with
170 | the terms of this License in conveying all material for which you do
171 | not control copyright. Those thus making or running the covered works
172 | for you must do so exclusively on your behalf, under your direction
173 | and control, on terms that prohibit them from making any copies of
174 | your copyrighted material outside their relationship with you.
175 |
176 | Conveying under any other circumstances is permitted solely under
177 | the conditions stated below. Sublicensing is not allowed; section 10
178 | makes it unnecessary.
179 |
180 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
181 |
182 | No covered work shall be deemed part of an effective technological
183 | measure under any applicable law fulfilling obligations under article
184 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
185 | similar laws prohibiting or restricting circumvention of such
186 | measures.
187 |
188 | When you convey a covered work, you waive any legal power to forbid
189 | circumvention of technological measures to the extent such circumvention
190 | is effected by exercising rights under this License with respect to
191 | the covered work, and you disclaim any intention to limit operation or
192 | modification of the work as a means of enforcing, against the work's
193 | users, your or third parties' legal rights to forbid circumvention of
194 | technological measures.
195 |
196 | 4. Conveying Verbatim Copies.
197 |
198 | You may convey verbatim copies of the Program's source code as you
199 | receive it, in any medium, provided that you conspicuously and
200 | appropriately publish on each copy an appropriate copyright notice;
201 | keep intact all notices stating that this License and any
202 | non-permissive terms added in accord with section 7 apply to the code;
203 | keep intact all notices of the absence of any warranty; and give all
204 | recipients a copy of this License along with the Program.
205 |
206 | You may charge any price or no price for each copy that you convey,
207 | and you may offer support or warranty protection for a fee.
208 |
209 | 5. Conveying Modified Source Versions.
210 |
211 | You may convey a work based on the Program, or the modifications to
212 | produce it from the Program, in the form of source code under the
213 | terms of section 4, provided that you also meet all of these conditions:
214 |
215 | a) The work must carry prominent notices stating that you modified
216 | it, and giving a relevant date.
217 |
218 | b) The work must carry prominent notices stating that it is
219 | released under this License and any conditions added under section
220 | 7. This requirement modifies the requirement in section 4 to
221 | "keep intact all notices".
222 |
223 | c) You must license the entire work, as a whole, under this
224 | License to anyone who comes into possession of a copy. This
225 | License will therefore apply, along with any applicable section 7
226 | additional terms, to the whole of the work, and all its parts,
227 | regardless of how they are packaged. This License gives no
228 | permission to license the work in any other way, but it does not
229 | invalidate such permission if you have separately received it.
230 |
231 | d) If the work has interactive user interfaces, each must display
232 | Appropriate Legal Notices; however, if the Program has interactive
233 | interfaces that do not display Appropriate Legal Notices, your
234 | work need not make them do so.
235 |
236 | A compilation of a covered work with other separate and independent
237 | works, which are not by their nature extensions of the covered work,
238 | and which are not combined with it such as to form a larger program,
239 | in or on a volume of a storage or distribution medium, is called an
240 | "aggregate" if the compilation and its resulting copyright are not
241 | used to limit the access or legal rights of the compilation's users
242 | beyond what the individual works permit. Inclusion of a covered work
243 | in an aggregate does not cause this License to apply to the other
244 | parts of the aggregate.
245 |
246 | 6. Conveying Non-Source Forms.
247 |
248 | You may convey a covered work in object code form under the terms
249 | of sections 4 and 5, provided that you also convey the
250 | machine-readable Corresponding Source under the terms of this License,
251 | in one of these ways:
252 |
253 | a) Convey the object code in, or embodied in, a physical product
254 | (including a physical distribution medium), accompanied by the
255 | Corresponding Source fixed on a durable physical medium
256 | customarily used for software interchange.
257 |
258 | b) Convey the object code in, or embodied in, a physical product
259 | (including a physical distribution medium), accompanied by a
260 | written offer, valid for at least three years and valid for as
261 | long as you offer spare parts or customer support for that product
262 | model, to give anyone who possesses the object code either (1) a
263 | copy of the Corresponding Source for all the software in the
264 | product that is covered by this License, on a durable physical
265 | medium customarily used for software interchange, for a price no
266 | more than your reasonable cost of physically performing this
267 | conveying of source, or (2) access to copy the
268 | Corresponding Source from a network server at no charge.
269 |
270 | c) Convey individual copies of the object code with a copy of the
271 | written offer to provide the Corresponding Source. This
272 | alternative is allowed only occasionally and noncommercially, and
273 | only if you received the object code with such an offer, in accord
274 | with subsection 6b.
275 |
276 | d) Convey the object code by offering access from a designated
277 | place (gratis or for a charge), and offer equivalent access to the
278 | Corresponding Source in the same way through the same place at no
279 | further charge. You need not require recipients to copy the
280 | Corresponding Source along with the object code. If the place to
281 | copy the object code is a network server, the Corresponding Source
282 | may be on a different server (operated by you or a third party)
283 | that supports equivalent copying facilities, provided you maintain
284 | clear directions next to the object code saying where to find the
285 | Corresponding Source. Regardless of what server hosts the
286 | Corresponding Source, you remain obligated to ensure that it is
287 | available for as long as needed to satisfy these requirements.
288 |
289 | e) Convey the object code using peer-to-peer transmission, provided
290 | you inform other peers where the object code and Corresponding
291 | Source of the work are being offered to the general public at no
292 | charge under subsection 6d.
293 |
294 | A separable portion of the object code, whose source code is excluded
295 | from the Corresponding Source as a System Library, need not be
296 | included in conveying the object code work.
297 |
298 | A "User Product" is either (1) a "consumer product", which means any
299 | tangible personal property which is normally used for personal, family,
300 | or household purposes, or (2) anything designed or sold for incorporation
301 | into a dwelling. In determining whether a product is a consumer product,
302 | doubtful cases shall be resolved in favor of coverage. For a particular
303 | product received by a particular user, "normally used" refers to a
304 | typical or common use of that class of product, regardless of the status
305 | of the particular user or of the way in which the particular user
306 | actually uses, or expects or is expected to use, the product. A product
307 | is a consumer product regardless of whether the product has substantial
308 | commercial, industrial or non-consumer uses, unless such uses represent
309 | the only significant mode of use of the product.
310 |
311 | "Installation Information" for a User Product means any methods,
312 | procedures, authorization keys, or other information required to install
313 | and execute modified versions of a covered work in that User Product from
314 | a modified version of its Corresponding Source. The information must
315 | suffice to ensure that the continued functioning of the modified object
316 | code is in no case prevented or interfered with solely because
317 | modification has been made.
318 |
319 | If you convey an object code work under this section in, or with, or
320 | specifically for use in, a User Product, and the conveying occurs as
321 | part of a transaction in which the right of possession and use of the
322 | User Product is transferred to the recipient in perpetuity or for a
323 | fixed term (regardless of how the transaction is characterized), the
324 | Corresponding Source conveyed under this section must be accompanied
325 | by the Installation Information. But this requirement does not apply
326 | if neither you nor any third party retains the ability to install
327 | modified object code on the User Product (for example, the work has
328 | been installed in ROM).
329 |
330 | The requirement to provide Installation Information does not include a
331 | requirement to continue to provide support service, warranty, or updates
332 | for a work that has been modified or installed by the recipient, or for
333 | the User Product in which it has been modified or installed. Access to a
334 | network may be denied when the modification itself materially and
335 | adversely affects the operation of the network or violates the rules and
336 | protocols for communication across the network.
337 |
338 | Corresponding Source conveyed, and Installation Information provided,
339 | in accord with this section must be in a format that is publicly
340 | documented (and with an implementation available to the public in
341 | source code form), and must require no special password or key for
342 | unpacking, reading or copying.
343 |
344 | 7. Additional Terms.
345 |
346 | "Additional permissions" are terms that supplement the terms of this
347 | License by making exceptions from one or more of its conditions.
348 | Additional permissions that are applicable to the entire Program shall
349 | be treated as though they were included in this License, to the extent
350 | that they are valid under applicable law. If additional permissions
351 | apply only to part of the Program, that part may be used separately
352 | under those permissions, but the entire Program remains governed by
353 | this License without regard to the additional permissions.
354 |
355 | When you convey a copy of a covered work, you may at your option
356 | remove any additional permissions from that copy, or from any part of
357 | it. (Additional permissions may be written to require their own
358 | removal in certain cases when you modify the work.) You may place
359 | additional permissions on material, added by you to a covered work,
360 | for which you have or can give appropriate copyright permission.
361 |
362 | Notwithstanding any other provision of this License, for material you
363 | add to a covered work, you may (if authorized by the copyright holders of
364 | that material) supplement the terms of this License with terms:
365 |
366 | a) Disclaiming warranty or limiting liability differently from the
367 | terms of sections 15 and 16 of this License; or
368 |
369 | b) Requiring preservation of specified reasonable legal notices or
370 | author attributions in that material or in the Appropriate Legal
371 | Notices displayed by works containing it; or
372 |
373 | c) Prohibiting misrepresentation of the origin of that material, or
374 | requiring that modified versions of such material be marked in
375 | reasonable ways as different from the original version; or
376 |
377 | d) Limiting the use for publicity purposes of names of licensors or
378 | authors of the material; or
379 |
380 | e) Declining to grant rights under trademark law for use of some
381 | trade names, trademarks, or service marks; or
382 |
383 | f) Requiring indemnification of licensors and authors of that
384 | material by anyone who conveys the material (or modified versions of
385 | it) with contractual assumptions of liability to the recipient, for
386 | any liability that these contractual assumptions directly impose on
387 | those licensors and authors.
388 |
389 | All other non-permissive additional terms are considered "further
390 | restrictions" within the meaning of section 10. If the Program as you
391 | received it, or any part of it, contains a notice stating that it is
392 | governed by this License along with a term that is a further
393 | restriction, you may remove that term. If a license document contains
394 | a further restriction but permits relicensing or conveying under this
395 | License, you may add to a covered work material governed by the terms
396 | of that license document, provided that the further restriction does
397 | not survive such relicensing or conveying.
398 |
399 | If you add terms to a covered work in accord with this section, you
400 | must place, in the relevant source files, a statement of the
401 | additional terms that apply to those files, or a notice indicating
402 | where to find the applicable terms.
403 |
404 | Additional terms, permissive or non-permissive, may be stated in the
405 | form of a separately written license, or stated as exceptions;
406 | the above requirements apply either way.
407 |
408 | 8. Termination.
409 |
410 | You may not propagate or modify a covered work except as expressly
411 | provided under this License. Any attempt otherwise to propagate or
412 | modify it is void, and will automatically terminate your rights under
413 | this License (including any patent licenses granted under the third
414 | paragraph of section 11).
415 |
416 | However, if you cease all violation of this License, then your
417 | license from a particular copyright holder is reinstated (a)
418 | provisionally, unless and until the copyright holder explicitly and
419 | finally terminates your license, and (b) permanently, if the copyright
420 | holder fails to notify you of the violation by some reasonable means
421 | prior to 60 days after the cessation.
422 |
423 | Moreover, your license from a particular copyright holder is
424 | reinstated permanently if the copyright holder notifies you of the
425 | violation by some reasonable means, this is the first time you have
426 | received notice of violation of this License (for any work) from that
427 | copyright holder, and you cure the violation prior to 30 days after
428 | your receipt of the notice.
429 |
430 | Termination of your rights under this section does not terminate the
431 | licenses of parties who have received copies or rights from you under
432 | this License. If your rights have been terminated and not permanently
433 | reinstated, you do not qualify to receive new licenses for the same
434 | material under section 10.
435 |
436 | 9. Acceptance Not Required for Having Copies.
437 |
438 | You are not required to accept this License in order to receive or
439 | run a copy of the Program. Ancillary propagation of a covered work
440 | occurring solely as a consequence of using peer-to-peer transmission
441 | to receive a copy likewise does not require acceptance. However,
442 | nothing other than this License grants you permission to propagate or
443 | modify any covered work. These actions infringe copyright if you do
444 | not accept this License. Therefore, by modifying or propagating a
445 | covered work, you indicate your acceptance of this License to do so.
446 |
447 | 10. Automatic Licensing of Downstream Recipients.
448 |
449 | Each time you convey a covered work, the recipient automatically
450 | receives a license from the original licensors, to run, modify and
451 | propagate that work, subject to this License. You are not responsible
452 | for enforcing compliance by third parties with this License.
453 |
454 | An "entity transaction" is a transaction transferring control of an
455 | organization, or substantially all assets of one, or subdividing an
456 | organization, or merging organizations. If propagation of a covered
457 | work results from an entity transaction, each party to that
458 | transaction who receives a copy of the work also receives whatever
459 | licenses to the work the party's predecessor in interest had or could
460 | give under the previous paragraph, plus a right to possession of the
461 | Corresponding Source of the work from the predecessor in interest, if
462 | the predecessor has it or can get it with reasonable efforts.
463 |
464 | You may not impose any further restrictions on the exercise of the
465 | rights granted or affirmed under this License. For example, you may
466 | not impose a license fee, royalty, or other charge for exercise of
467 | rights granted under this License, and you may not initiate litigation
468 | (including a cross-claim or counterclaim in a lawsuit) alleging that
469 | any patent claim is infringed by making, using, selling, offering for
470 | sale, or importing the Program or any portion of it.
471 |
472 | 11. Patents.
473 |
474 | A "contributor" is a copyright holder who authorizes use under this
475 | License of the Program or a work on which the Program is based. The
476 | work thus licensed is called the contributor's "contributor version".
477 |
478 | A contributor's "essential patent claims" are all patent claims
479 | owned or controlled by the contributor, whether already acquired or
480 | hereafter acquired, that would be infringed by some manner, permitted
481 | by this License, of making, using, or selling its contributor version,
482 | but do not include claims that would be infringed only as a
483 | consequence of further modification of the contributor version. For
484 | purposes of this definition, "control" includes the right to grant
485 | patent sublicenses in a manner consistent with the requirements of
486 | this License.
487 |
488 | Each contributor grants you a non-exclusive, worldwide, royalty-free
489 | patent license under the contributor's essential patent claims, to
490 | make, use, sell, offer for sale, import and otherwise run, modify and
491 | propagate the contents of its contributor version.
492 |
493 | In the following three paragraphs, a "patent license" is any express
494 | agreement or commitment, however denominated, not to enforce a patent
495 | (such as an express permission to practice a patent or covenant not to
496 | sue for patent infringement). To "grant" such a patent license to a
497 | party means to make such an agreement or commitment not to enforce a
498 | patent against the party.
499 |
500 | If you convey a covered work, knowingly relying on a patent license,
501 | and the Corresponding Source of the work is not available for anyone
502 | to copy, free of charge and under the terms of this License, through a
503 | publicly available network server or other readily accessible means,
504 | then you must either (1) cause the Corresponding Source to be so
505 | available, or (2) arrange to deprive yourself of the benefit of the
506 | patent license for this particular work, or (3) arrange, in a manner
507 | consistent with the requirements of this License, to extend the patent
508 | license to downstream recipients. "Knowingly relying" means you have
509 | actual knowledge that, but for the patent license, your conveying the
510 | covered work in a country, or your recipient's use of the covered work
511 | in a country, would infringe one or more identifiable patents in that
512 | country that you have reason to believe are valid.
513 |
514 | If, pursuant to or in connection with a single transaction or
515 | arrangement, you convey, or propagate by procuring conveyance of, a
516 | covered work, and grant a patent license to some of the parties
517 | receiving the covered work authorizing them to use, propagate, modify
518 | or convey a specific copy of the covered work, then the patent license
519 | you grant is automatically extended to all recipients of the covered
520 | work and works based on it.
521 |
522 | A patent license is "discriminatory" if it does not include within
523 | the scope of its coverage, prohibits the exercise of, or is
524 | conditioned on the non-exercise of one or more of the rights that are
525 | specifically granted under this License. You may not convey a covered
526 | work if you are a party to an arrangement with a third party that is
527 | in the business of distributing software, under which you make payment
528 | to the third party based on the extent of your activity of conveying
529 | the work, and under which the third party grants, to any of the
530 | parties who would receive the covered work from you, a discriminatory
531 | patent license (a) in connection with copies of the covered work
532 | conveyed by you (or copies made from those copies), or (b) primarily
533 | for and in connection with specific products or compilations that
534 | contain the covered work, unless you entered into that arrangement,
535 | or that patent license was granted, prior to 28 March 2007.
536 |
537 | Nothing in this License shall be construed as excluding or limiting
538 | any implied license or other defenses to infringement that may
539 | otherwise be available to you under applicable patent law.
540 |
541 | 12. No Surrender of Others' Freedom.
542 |
543 | If conditions are imposed on you (whether by court order, agreement or
544 | otherwise) that contradict the conditions of this License, they do not
545 | excuse you from the conditions of this License. If you cannot convey a
546 | covered work so as to satisfy simultaneously your obligations under this
547 | License and any other pertinent obligations, then as a consequence you may
548 | not convey it at all. For example, if you agree to terms that obligate you
549 | to collect a royalty for further conveying from those to whom you convey
550 | the Program, the only way you could satisfy both those terms and this
551 | License would be to refrain entirely from conveying the Program.
552 |
553 | 13. Use with the GNU Affero General Public License.
554 |
555 | Notwithstanding any other provision of this License, you have
556 | permission to link or combine any covered work with a work licensed
557 | under version 3 of the GNU Affero General Public License into a single
558 | combined work, and to convey the resulting work. The terms of this
559 | License will continue to apply to the part which is the covered work,
560 | but the special requirements of the GNU Affero General Public License,
561 | section 13, concerning interaction through a network will apply to the
562 | combination as such.
563 |
564 | 14. Revised Versions of this License.
565 |
566 | The Free Software Foundation may publish revised and/or new versions of
567 | the GNU General Public License from time to time. Such new versions will
568 | be similar in spirit to the present version, but may differ in detail to
569 | address new problems or concerns.
570 |
571 | Each version is given a distinguishing version number. If the
572 | Program specifies that a certain numbered version of the GNU General
573 | Public License "or any later version" applies to it, you have the
574 | option of following the terms and conditions either of that numbered
575 | version or of any later version published by the Free Software
576 | Foundation. If the Program does not specify a version number of the
577 | GNU General Public License, you may choose any version ever published
578 | by the Free Software Foundation.
579 |
580 | If the Program specifies that a proxy can decide which future
581 | versions of the GNU General Public License can be used, that proxy's
582 | public statement of acceptance of a version permanently authorizes you
583 | to choose that version for the Program.
584 |
585 | Later license versions may give you additional or different
586 | permissions. However, no additional obligations are imposed on any
587 | author or copyright holder as a result of your choosing to follow a
588 | later version.
589 |
590 | 15. Disclaimer of Warranty.
591 |
592 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
593 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
594 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
595 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
596 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
597 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
598 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
599 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
600 |
601 | 16. Limitation of Liability.
602 |
603 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
604 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
605 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
606 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
607 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
608 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
609 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
610 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
611 | SUCH DAMAGES.
612 |
613 | 17. Interpretation of Sections 15 and 16.
614 |
615 | If the disclaimer of warranty and limitation of liability provided
616 | above cannot be given local legal effect according to their terms,
617 | reviewing courts shall apply local law that most closely approximates
618 | an absolute waiver of all civil liability in connection with the
619 | Program, unless a warranty or assumption of liability accompanies a
620 | copy of the Program in return for a fee.
621 |
622 | END OF TERMS AND CONDITIONS
623 |
624 | How to Apply These Terms to Your New Programs
625 |
626 | If you develop a new program, and you want it to be of the greatest
627 | possible use to the public, the best way to achieve this is to make it
628 | free software which everyone can redistribute and change under these terms.
629 |
630 | To do so, attach the following notices to the program. It is safest
631 | to attach them to the start of each source file to most effectively
632 | state the exclusion of warranty; and each file should have at least
633 | the "copyright" line and a pointer to where the full notice is found.
634 |
635 |
636 | Copyright (C)
637 |
638 | This program is free software: you can redistribute it and/or modify
639 | it under the terms of the GNU General Public License as published by
640 | the Free Software Foundation, either version 3 of the License, or
641 | (at your option) any later version.
642 |
643 | This program is distributed in the hope that it will be useful,
644 | but WITHOUT ANY WARRANTY; without even the implied warranty of
645 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
646 | GNU General Public License for more details.
647 |
648 | You should have received a copy of the GNU General Public License
649 | along with this program. If not, see .
650 |
651 | Also add information on how to contact you by electronic and paper mail.
652 |
653 | If the program does terminal interaction, make it output a short
654 | notice like this when it starts in an interactive mode:
655 |
656 | Copyright (C)
657 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
658 | This is free software, and you are welcome to redistribute it
659 | under certain conditions; type `show c' for details.
660 |
661 | The hypothetical commands `show w' and `show c' should show the appropriate
662 | parts of the General Public License. Of course, your program's commands
663 | might be different; for a GUI interface, you would use an "about box".
664 |
665 | You should also get your employer (if you work as a programmer) or school,
666 | if any, to sign a "copyright disclaimer" for the program, if necessary.
667 | For more information on this, and how to apply and follow the GNU GPL, see
668 | .
669 |
670 | The GNU General Public License does not permit incorporating your program
671 | into proprietary programs. If your program is a subroutine library, you
672 | may consider it more useful to permit linking proprietary applications with
673 | the library. If this is what you want to do, use the GNU Lesser General
674 | Public License instead of this License. But first, please read
675 | .
676 |
677 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------