亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? client.c

?? 使用Exlipse編寫的一個語音程序
?? C
字號:
/* * Implements the Client side of the Client/Server demo. * * It waits for the user to type in a line of text, sends the line of * text to the speech server, which returns a stream of bytes (the * synthesized wave samples). This client then plays the stream * of bytes at the local audio device. * * You must start the speech server first. You can do this by typing: * * gmake runserver * * at the same directory. To run this client, modify set the speech * server host (and port number if not 5555) at the Makefile, and then type: *  * gmake runcclient * * In the Makefile, you can also specify the sample rate you want * as the third argument (currently, the server supports only 8kHz and 16kHz). * * This C client should run across most UNIX implementations, as it * uses standard UNIX system libraries. * * For a complete specification of the protocol between client and server, * consult the document <code>Protocol.txt</code>. */#include <arpa/inet.h>#include <ctype.h>#include <errno.h>#include <fcntl.h>#include <netdb.h>#include <netinet/in.h>#include <stdio.h>#include <stdlib.h>#include <strings.h>#include <sys/audio.h>#include <sys/audioio.h>#include <sys/filio.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>#define TRUE 1#define FALSE 0#define SERVER_PORT 5555#define SERVER_HOST "sunlabs.east"#define AUDIO_DEVICE_FILE "/dev/audio"#define AUDIO_DEVICE_ENV_VAR "AUDIODEV"  // for SunRays#define DEFAULT_SAMPLE_RATE 8000#define ADDRESS_SIZE sizeof(struct sockaddr_in)#define AUDIO_BUFFER_SIZE 1024#define TEXT_INPUT_BUFFER_SIZE 1024#define STR_BUFFER_SIZE 10#define FIRST_SENTENCE "Type in what you want me to say."int connect_speech_server(char* server_host, int server_port);void run_tts_protocol(int sock_fd);int read_line(int sock_fd, char *buffer, int buffer_size);int send_tts_request(int sock_fd, char *tts_text);void receive_play_samples(int sock_fd, int number_samples);int open_audio_device();int set_pcm_linear();unsigned char short_to_ulaw(short sample);int is_string_nonempty(char *string, int length);/* our audio device file descriptor */int audio_fd;/* the sample rate */int sample_rate = DEFAULT_SAMPLE_RATE;/* show metrics */int metrics = 1;/* equals 1 if the first byte is received */int first_byte_received = 0;/* the start time */struct timeval start_time;/* the first byte time */struct timeval first_byte_time;/* the first sound time */struct timeval first_sound_time;/** * It first attempts a connection to the speech server. Then, * it waits for the user to type in a line of text, sends the line of * text to the speech server, which returns a stream of bytes (the * synthesized wave samples). This client then plays the stream * of bytes at the local audio device. * * Arguments (optional): * argv[1] : the host name of speech server * argv[2] : the port number where the speech server is listening * argv[3] : the sample rate * argv[4] : show metrics, 1 to show, 0 to not show */int main(int args, char *argv[]) {  int sock_fd;  int server_port;  char* server_host;    server_port = SERVER_PORT;  server_host = SERVER_HOST;  /* parse command line arguments for server hostname and port number */  if (args >= 2) {    server_host = argv[1];  }  if (args >= 3) {    server_port = atoi(argv[2]);  }  if (args >= 4) {    sample_rate = atoi(argv[3]);  }  if (args >= 5) {    metrics = atoi(argv[4]);  }  /* connect to the server */  sock_fd = connect_speech_server(server_host, server_port);  /* start running the TTS protocol */  run_tts_protocol(sock_fd);  /* do cleanup */  close(sock_fd);  return 0;}/** * Connects to the remote speech server at the given host and port, * and returns the socket file descriptor to the connection. * * Arguments: * server_host: the host name of the speech server * server_port: the port on which the speech server is listening * * Returns: * a file descriptor of the socket */int connect_speech_server(char* server_host, int server_port) {    int sock_fd;  struct sockaddr_in server = {AF_INET, SERVER_PORT};  struct hostent *hp;  /* obtain the IP address */  hp = gethostbyname(server_host);  if (hp == NULL) {    perror("invalid hostname");    exit(1);  }  /* set the IP address and port */  bcopy((char *)hp->h_addr, (char *)&server.sin_addr, hp->h_length);  server.sin_port = htons(server_port);    /* set up the transport end point */  if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {    perror("socket call failed");    exit(1);  }  /* connect to the server */  if (connect(sock_fd, (struct sockaddr *) &server, ADDRESS_SIZE) == -1) {    perror("connect call failed");    exit(1);  }  return sock_fd;}/** * Runs the TTS protocol. * It waits for the user to type in a line of text, sends the line of * text to the speech server, which returns a stream of bytes (the * synthesized wave samples). This client then plays the stream * of bytes at the local audio device. * * Arguments: * sock_fd  the socket file descriptor */void run_tts_protocol(int sock_fd) {  char buffer[STR_BUFFER_SIZE];  char input_buffer[TEXT_INPUT_BUFFER_SIZE];  ssize_t nread;  /* read the "READY" line from the Server */  nread = recv(sock_fd, buffer, 6, 0);  buffer[nread] = '\0';  if (strcmp(buffer, "READY\n") == 0) {    if (send_tts_request(sock_fd, FIRST_SENTENCE) == -1) {      return;    }        input_buffer[0] = '\0';    printf("Say       : ");    while (fgets(input_buffer, TEXT_INPUT_BUFFER_SIZE, stdin) != NULL) {      if (is_string_nonempty(input_buffer, strlen(input_buffer)) &&	  send_tts_request(sock_fd, input_buffer) == -1) {	return;      }      input_buffer[0] = '\0';      printf("Say       : ");    }  }  send(sock_fd, "DONE\n", 5, 0);  /* drain all the audio before returning */  ioctl(audio_fd, AUDIO_DRAIN, 0);  printf("ALL DONE\n");}/** * Sends a TTS request of the given text to the given socket. * * Arguments: * sock_fd : socket file descriptor * tts_text : the text to perform TTS * * Returns: * 0 if everything's fine, -1 if any error occurred */int send_tts_request(int sock_fd, char *tts_text) {  int nsend;  char tts_text_str[TEXT_INPUT_BUFFER_SIZE];  int text_length;  char number_samples_str[STR_BUFFER_SIZE];  int number_samples;  int input_length;  input_length = strlen(tts_text);    if (tts_text[input_length - 1] == '\n') {    tts_text[input_length - 1] = '\0';  }  sprintf(tts_text_str, "TTS\n%d\n%s\n", sample_rate, tts_text);  text_length = strlen(tts_text_str);  /* record the time the request is sent */  if (metrics) {    gettimeofday(&start_time, NULL);    first_byte_received = 0;  }  /*   * send "TTS\n<sample_rate>\n<text>\n" (sent together to avoid    * repetitive send calls)   */  nsend = send(sock_fd, tts_text_str, text_length, 0);  do {    read_line(sock_fd, number_samples_str, STR_BUFFER_SIZE);                                              /* how many samples? */    if (strcmp(number_samples_str, "-2") == 0) {      printf("TTS Error\n");      return -1;    }    if (strcmp(number_samples_str, "-1") != 0) {      number_samples = atoi(number_samples_str);            printf("Receiving : %d samples\n", number_samples);      receive_play_samples(sock_fd, number_samples);    }  }  while (strcmp(number_samples_str, "-1") != 0 &&	 strcmp(number_samples_str, "-2") != 0);  if (metrics) {    long elapsed_time =      (first_byte_time.tv_sec - start_time.tv_sec)*1000 +       (first_byte_time.tv_usec - start_time.tv_usec)/1000;    printf("FirstByte : %li ms\n", elapsed_time);  }  return 0;}/** * Receive the given number of wave samples and play it to the audio * device. * * Arguments: * sock_fd : the socket file descriptor * number_samples : the number of wave samples to receive from the socket */void receive_play_samples(int sock_fd, int number_samples) {  int nread;  int nsend;  int bytes_to_read;  int bytes_remaining;  short socket_buffer[AUDIO_BUFFER_SIZE];  bytes_remaining = number_samples;  open_audio_device();  /* read the samples from the socket, and write it to the audio device */  while (bytes_remaining > 0) {    if (bytes_remaining >= AUDIO_BUFFER_SIZE) {      bytes_to_read = AUDIO_BUFFER_SIZE;    }    else {      bytes_to_read = bytes_remaining;    }        if ((nread = read(sock_fd, socket_buffer, bytes_to_read)) == -1) {      perror("error reading samples");    }    if (metrics && !first_byte_received) {      gettimeofday(&first_byte_time, NULL);      first_byte_received = 1;    }    if ((nsend = write(audio_fd, socket_buffer, nread)) == -1) {      perror("error playing samples");    }    bytes_remaining -= nread;  }  close(audio_fd);}/** * Reads a line of input from the given file descriptor, and save it * in the given buffer. * * Arguments: * sock_fd : the (socket) file descriptor * buffer : the buffer to save the line read * buffer_size : size of the buffer * * Returns: * The number of characters in the line, not including end of line character. */  int read_line(int sock_fd, char *buffer, int buffer_size) {  int i;  char rc;  for (i = 0; i < (buffer_size-1); i++) {    read(sock_fd, &rc, 1);    buffer[i] = rc;    if (rc == '\n') {      break;    }  }  buffer[i] = '\0';   return i;}/** * Returns 1 if the given string contains text, ie, it does not only * contain the space, newline or tab characters. * * Arguments: * string : the input string * length : the string length */int is_string_nonempty(char *string, int length) {  int i;  for (i = 0; i < length; i++) {    if (string[i] != ' ' && string[i] != '\n' && string[i] != '\t') {      return 1;    }  }  return 0;}/** * Opens the audio device file, and returns the file descriptor, * or -1 if an error occurred. * * Returns: * The audio device file descriptor. */int open_audio_device() {    char *audio_device = AUDIO_DEVICE_FILE;  if ((audio_fd = open(audio_device, O_WRONLY)) == -1) {    /* the device might be a SunRay, so get the $AUDIODEV env var */    audio_device = getenv(AUDIO_DEVICE_ENV_VAR);      if (audio_device != NULL) {      if ((audio_fd = open(audio_device, O_RDWR)) == -1) {	perror("Can't open audio device with environment variable");	exit(1);      }    }    else {      perror("Can't open audio device");      exit(1);    }  }  if (set_pcm_linear() == FALSE) {    perror("fail to set audio device to PCM linear");    exit(1);  }  return audio_fd;}/** * Attempts to set the audio format of the audio device to 16-bit * PCM linear, at the given sample rate. * * Returns: * TRUE if the audio format was set successfully * FALSE otherwise */ int set_pcm_linear() {  int set_status;  audio_info_t info;  // AUDIO_INITINFO(&info);  ioctl(audio_fd, AUDIO_GETINFO, &info);  info.play.encoding = AUDIO_ENCODING_LINEAR;  info.play.precision = 16;  info.play.channels = 1;  info.play.sample_rate = sample_rate;  set_status = ioctl(audio_fd, AUDIO_SETINFO, &info);  if (set_status == -1) {    return FALSE;  } else {    return TRUE;  }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久不卡网国产精品一区| 欧美videossexotv100| 国产成人av电影在线| 久久国产精品99久久人人澡| 亚洲国产一区在线观看| 亚洲国产精品尤物yw在线观看| 亚洲伦理在线免费看| 亚洲欧美激情小说另类| 一区二区视频在线| 亚洲一区免费视频| 五月综合激情日本mⅴ| 日韩不卡一区二区| 韩国av一区二区三区四区| 国产一区二区成人久久免费影院| 国产一区二区三区四区五区入口| 狠狠色丁香久久婷婷综合丁香| 国产一区二区三区四| 国产91在线观看丝袜| 成人黄色大片在线观看| 色综合久久88色综合天天6| 欧美日韩一区不卡| 26uuu久久综合| 国产精品午夜在线| 亚洲国产精品一区二区久久恐怖片| 亚洲成人免费观看| 久久99精品一区二区三区三区| 国产精品911| 欧美日韩综合不卡| 日韩精品中午字幕| 国产精品天天摸av网| 亚洲一区二区av在线| 日本不卡一区二区| 国产99精品国产| 欧美久久久久免费| 欧美国产精品一区| 日韩精品1区2区3区| 成+人+亚洲+综合天堂| 欧美日韩在线三区| 一区二区视频在线看| 琪琪久久久久日韩精品| av在线不卡免费看| 欧美一区日本一区韩国一区| 国产精品萝li| 久久99精品网久久| 欧美色图一区二区三区| 欧美国产日韩a欧美在线观看| 亚洲制服丝袜av| 成人一区二区三区视频在线观看| 欧美视频在线观看一区二区| 国产欧美日韩久久| 老司机免费视频一区二区三区| 色婷婷久久久综合中文字幕| wwwwww.欧美系列| 天堂在线亚洲视频| 色视频成人在线观看免| 久久蜜臀中文字幕| 蜜臀av亚洲一区中文字幕| 一本色道久久综合亚洲91| 国产日韩在线不卡| 久久不见久久见免费视频7| 欧美日韩精品一区视频| 中文字幕一区二区三区不卡| 国内外成人在线| 欧美一区二区在线看| 亚洲国产精品一区二区www在线| 成人中文字幕合集| 久久先锋资源网| 极品少妇一区二区| 欧美一区二区三区不卡| 日本女优在线视频一区二区| 欧美日韩日本视频| 亚洲chinese男男1069| 欧美日本一区二区| 婷婷综合五月天| 欧美乱妇一区二区三区不卡视频| 亚洲在线中文字幕| 欧美在线你懂的| 亚洲一二三区不卡| 欧美伦理电影网| 免费成人在线视频观看| 精品久久一区二区| 国产曰批免费观看久久久| 精品国产乱码久久久久久闺蜜| 麻豆国产一区二区| 精品美女一区二区三区| 久久99精品久久久久久| 久久久精品日韩欧美| 成人网男人的天堂| 亚洲美女屁股眼交| 欧美精品18+| 激情小说欧美图片| 国产精品伦一区| 91久久精品国产91性色tv| 五月天婷婷综合| 精品成人佐山爱一区二区| 国产一区二区视频在线| 最新高清无码专区| 欧美人与性动xxxx| 久久精品国产第一区二区三区| 久久久不卡影院| 在线视频一区二区三| 强制捆绑调教一区二区| 日本一区二区高清| 欧美日韩日本视频| 国产69精品久久99不卡| 亚洲自拍偷拍欧美| 欧美成人在线直播| 色哟哟一区二区| caoporm超碰国产精品| 一区二区在线观看av| 精品粉嫩aⅴ一区二区三区四区| 国产v综合v亚洲欧| 午夜一区二区三区视频| 久久久精品黄色| 欧美精选一区二区| 丁香网亚洲国际| 日韩av电影天堂| 亚洲国产精品精华液ab| 51精品视频一区二区三区| 国产成人综合亚洲网站| 日韩中文字幕麻豆| 亚洲欧美在线视频| 精品99一区二区三区| 色综合天天综合狠狠| 国产一区二区三区国产| 亚洲一卡二卡三卡四卡五卡| 国产精品视频一二| 欧美一区二区三区四区视频| 91在线精品秘密一区二区| 久久97超碰国产精品超碰| 亚洲图片有声小说| 亚洲三级电影网站| 欧美高清在线精品一区| 精品国产乱码久久久久久免费| 欧美色综合影院| 91玉足脚交白嫩脚丫在线播放| 极品少妇xxxx偷拍精品少妇| 日韩精品三区四区| 亚洲va韩国va欧美va| 一区二区在线观看视频| 综合自拍亚洲综合图不卡区| 国产日韩av一区二区| 久久综合九色综合97婷婷| 91精品国产综合久久久久久久久久| 色婷婷国产精品综合在线观看| 不卡在线视频中文字幕| 国产精品一区二区男女羞羞无遮挡| 日韩精品亚洲一区二区三区免费| 一区二区三区在线观看国产| 亚洲欧美经典视频| 尤物视频一区二区| 亚洲线精品一区二区三区| 亚洲欧美日韩在线播放| 亚洲激情成人在线| 亚洲一区二三区| 亚洲午夜精品一区二区三区他趣| 专区另类欧美日韩| 亚洲最大成人网4388xx| 亚洲伊人色欲综合网| 午夜电影一区二区| 另类小说图片综合网| 国产美女精品人人做人人爽 | 国产精品影视在线| 捆绑调教一区二区三区| 精品一区二区三区在线播放视频 | 亚洲一区视频在线| 亚洲电影视频在线| 日韩成人精品在线| 韩日欧美一区二区三区| 高清shemale亚洲人妖| 成人爽a毛片一区二区免费| 99精品视频免费在线观看| 91九色02白丝porn| 欧美一区二区三区婷婷月色| 久久久五月婷婷| 中文字幕亚洲在| 香蕉成人伊视频在线观看| 久久99久久精品| 91丝袜国产在线播放| 欧美色综合网站| 久久日韩精品一区二区五区| 国产精品美女久久久久久久| 亚洲综合色自拍一区| 成人手机电影网| 欧美三级一区二区| 欧美精品一区二区三区在线| 亚洲视频网在线直播| 日韩高清中文字幕一区| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 欧美激情在线一区二区| 亚洲午夜精品在线| 国产黑丝在线一区二区三区| 欧美在线一区二区| 国产网站一区二区| 亚洲成a人v欧美综合天堂| 国产伦理精品不卡| 欧美日韩在线播放三区四区| 国产蜜臀av在线一区二区三区| 一区二区三区高清不卡| 国产精品中文字幕一区二区三区|