Permalink
Browse files

project init, and codes push

  • Loading branch information...
0 parents commit d9adc8df1e0064e7d859644ad7031078069fdab5 @yueyoum committed Aug 2, 2012
@@ -0,0 +1,5 @@
+*.o
+*.pyc
+*.bak
+wsound
+libwsound.so
@@ -0,0 +1,38 @@
+OBJECTS = sound.o decode_mp3.o
+
+PWD = `pwd`
+
+
+.PHONY:all
+all: wsound libwsound.so
+
+wsound: $(OBJECTS)
+ gcc -o wsound $(OBJECTS) \
+ -L ./depends/ao/lib/ \
+ -L ./depends/mpg123/lib/ \
+ -Wl,-rpath,$(PWD)/depends/ao/lib/,-rpath,$(PWD)/depends/mpg123/lib/ \
+ -lao -lmpg123
+
+libwsound.so: $(OBJECTS)
+ gcc -o libwsound.so $(OBJECTS) \
+ -DSHAREOBJ -fPIC -shared \
+ -L ./depends/ao/lib/ \
+ -L ./depends/mpg123/lib/ \
+ -Wl,-rpath,$(PWD)/depends/ao/lib/,-rpath,$(PWD)/depends/mpg123/lib/ \
+ -lao -lmpg123
+
+
+sound.o: sound.c sound.h
+ gcc -c sound.c \
+ -I ./depends/ao/include/ -Wall
+
+decode_mp3.o: decode_mp3.c sound.h
+ gcc -c decode_mp3.c \
+ -I ./depends/mpg123/include/ \
+ -I ./depends/ao/include/ \
+ -Wall
+
+
+.PHONY:clean
+clean:
+ -rm -f wsound libwsound.so $(OBJECTS)
@@ -0,0 +1,26 @@
+## 背景 ##
+> 初衷是因为要看大量的英文文档,难免需要翻译。
+
+> 先用Python做了一个google translate的程序。
+
+> 但在使用中发现,如果不知道单词的发音,很难记住新单词.
+
+> 所以就有了这个协助发音的程序
+
+## 说明 ##
+> C 程序使用 libmpg123 解码mp3, libao播放。
+
+> 进入项目目录中 make , 就会生成两个文件:
+
+> * wsound : ./wsound "MUSIC FILE" 可以播放mp3
+
+> * libwsound.so : 动态链接库, 其中的 <code>void decode(const char \*)</code> 提供给Python调用。
+
+> 运行 googletrans.py 后,输入 字符 回车后翻译,输入 s 发音,输入 exit 退出
+
+## 问题 ##
+> 貌似libao动态链接库的问题,需要大家自己再编译一遍 libao
+
+> 其实整个项目很简单,大家如果有需要自己编先编译 libao, libmpg123
+
+> 然后根据自己的需要修改 Makefile 和 googletrans.py
@@ -0,0 +1,99 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "mpg123.h"
+#include "sound.h"
+#include "ao/ao.h"
+
+
+static void cleanup(mpg123_handle *mh)
+{
+ mpg123_close(mh);
+ mpg123_delete(mh);
+ mpg123_exit();
+}
+
+
+int decode(const char *file)
+{
+ mpg123_handle *mh = NULL;
+ unsigned char *buffer = NULL;
+ size_t buffer_size = 0;
+ size_t done = 0;
+ int err = MPG123_OK;
+
+ int channels = 0;
+ int encoding = 0;
+ long rate = 0;
+
+ ao_device *device;
+
+ err = mpg123_init();
+ if(err != MPG123_OK || (mh = mpg123_new(NULL, &err)) == NULL)
+ {
+ fprintf(stderr, "setup error\n");
+ cleanup(mh);
+ exit(1);
+ }
+
+
+ if( mpg123_open(mh, file) != MPG123_OK ||
+ mpg123_getformat(mh, &rate, &channels, &encoding) != MPG123_OK )
+ {
+ fprintf(stderr, "getformat error\n");
+ cleanup(mh);
+ exit(2);
+ }
+
+
+ //printf("rate = %ld\n", rate);
+ //printf("channels = %d\n", channels);
+ //printf("encoding_16: %d\n", encoding == MPG123_ENC_SIGNED_16);
+
+ if(encoding != MPG123_ENC_SIGNED_16 && encoding != MPG123_ENC_FLOAT_32)
+ {
+ fprintf(stderr, "bad encoding\n");
+ cleanup(mh);
+ exit(3);
+ }
+
+ mpg123_format_none(mh);
+ mpg123_format(mh, rate, channels, encoding);
+
+ sound_init(channels, rate, &device);
+
+ buffer_size = mpg123_outblock(mh);
+ buffer = (unsigned char *)malloc(buffer_size * sizeof(char));
+
+ //printf("buff_size = %u\n", buffer_size);
+
+
+ while( mpg123_read(mh, buffer, buffer_size, &done) == MPG123_OK )
+ {
+ sound_speak((char *)buffer, buffer_size, device);
+ }
+
+ free(buffer);
+
+ sound_shutdown(device);
+
+ cleanup(mh);
+ return 0;
+}
+
+#ifndef SHAREOBJ
+
+int main(int argc, char *argv[])
+{
+ if( argc != 2)
+ {
+ fprintf(stderr, "need argument\n");
+ exit(1);
+ }
+
+ decode(argv[1]);
+ return 0;
+}
+
+#endif
@@ -0,0 +1,139 @@
+/*
+ *
+ * ao.h
+ *
+ * Original Copyright (C) Aaron Holtzman - May 1999
+ * Modifications Copyright (C) Stan Seibert - July 2000, July 2001
+ * More Modifications Copyright (C) Jack Moffitt - October 2000
+ *
+ * This file is part of libao, a cross-platform audio outputlibrary. See
+ * README for a history of this source code.
+ *
+ * libao is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * libao is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#ifndef __AO_H__
+#define __AO_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include "os_types.h"
+
+/* --- Constants ---*/
+
+#define AO_TYPE_LIVE 1
+#define AO_TYPE_FILE 2
+
+
+#define AO_ENODRIVER 1
+#define AO_ENOTFILE 2
+#define AO_ENOTLIVE 3
+#define AO_EBADOPTION 4
+#define AO_EOPENDEVICE 5
+#define AO_EOPENFILE 6
+#define AO_EFILEEXISTS 7
+#define AO_EBADFORMAT 8
+
+#define AO_EFAIL 100
+
+
+#define AO_FMT_LITTLE 1
+#define AO_FMT_BIG 2
+#define AO_FMT_NATIVE 4
+
+/* --- Structures --- */
+
+typedef struct ao_info {
+ int type; /* live output or file output? */
+ char *name; /* full name of driver */
+ char *short_name; /* short name of driver */
+ char *author; /* driver author */
+ char *comment; /* driver comment */
+ int preferred_byte_format;
+ int priority;
+ char **options;
+ int option_count;
+} ao_info;
+
+typedef struct ao_functions ao_functions;
+typedef struct ao_device ao_device;
+
+typedef struct ao_sample_format {
+ int bits; /* bits per sample */
+ int rate; /* samples per second (in a single channel) */
+ int channels; /* number of audio channels */
+ int byte_format; /* Byte ordering in sample, see constants below */
+ char *matrix; /* input channel location/ordering */
+} ao_sample_format;
+
+typedef struct ao_option {
+ char *key;
+ char *value;
+ struct ao_option *next;
+} ao_option;
+
+#if defined(AO_BUILDING_LIBAO)
+#include "ao_private.h"
+#endif
+
+/* --- Functions --- */
+
+/* library setup/teardown */
+void ao_initialize(void);
+void ao_shutdown(void);
+
+/* device setup/playback/teardown */
+int ao_append_global_option(const char *key,
+ const char *value);
+int ao_append_option(ao_option **options,
+ const char *key,
+ const char *value);
+void ao_free_options(ao_option *options);
+ao_device* ao_open_live(int driver_id,
+ ao_sample_format *format,
+ ao_option *option);
+ao_device* ao_open_file(int driver_id,
+ const char *filename,
+ int overwrite,
+ ao_sample_format *format,
+ ao_option *option);
+
+int ao_play(ao_device *device,
+ char *output_samples,
+ uint_32 num_bytes);
+int ao_close(ao_device *device);
+
+/* driver information */
+int ao_driver_id(const char *short_name);
+int ao_default_driver_id(void);
+ao_info *ao_driver_info(int driver_id);
+ao_info **ao_driver_info_list(int *driver_count);
+char *ao_file_extension(int driver_id);
+
+/* miscellaneous */
+int ao_is_big_endian(void);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __AO_H__ */
@@ -0,0 +1,39 @@
+/*
+ *
+ * os_types.h
+ *
+ * Original Copyright (C) Aaron Holtzman - May 1999
+ * Modifications Copyright (C) Stan Seibert - July 2000
+ *
+ * This file is part of libao, a cross-platform audio output library. See
+ * README for a history of this source code.
+ *
+ * libao is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * libao is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/* Set type sizes for this platform (Requires Autoconf) */
+
+#ifndef __OS_TYPES_H__
+#define __OS_TYPES_H__
+
+typedef unsigned char uint_8;
+typedef unsigned short uint_16;
+typedef unsigned int uint_32;
+typedef signed char sint_8;
+typedef signed short sint_16;
+typedef signed int sint_32;
+
+#endif /* __OS_TYPES_H__ */
Oops, something went wrong.

0 comments on commit d9adc8d

Please sign in to comment.