我正在用cmu sphinx写一个语音识别程序.它需要一个.raw
音频文件来处理.如何以原始格式从麦克风中获取声音?我已经google了.他们说我读了/dev/dsp
但是我找不到那个文件/设备.我在阿尔萨的ArchLinux.Linux version 3.2.9-1-pae
.
madper@myhost /dev % ls
agpgart ptmx tty23 tty58 vcs28 vcs62 vcsa39
autofs pts/ tty24 tty59 vcs29 vcs63 vcsa4
block/ random tty25 tty6 vcs3 vcs7 vcsa40
bsg/ rfkill tty26 tty60 vcs30 vcs8 vcsa41
btrfs-control rtc@ tty27 tty61 vcs31 vcs9 vcsa42
bus/ rtc0 tty28 tty62 vcs32 vcsa vcsa43
char/ sda tty29 tty63 vcs33 vcsa1 vcsa44
console sda1 tty3 tty7 vcs34 vcsa10 vcsa45
core@ sda2 tty30 tty8 vcs35 vcsa11 vcsa46
cpu/ sda3 …
Run Code Online (Sandbox Code Playgroud) 我有一个旧的代码需要编译与-m486
标志GCC
.但没有那面旗帜.然后我发现-mtune=i486
并且-arch=i486
我已经阅读了这个页面.但还是不知道哪一个最适合-m486
?
我需要将一些Mac数字(00163e2fbab7)转换为Mac字符串.(带":")
是否有一些很好的方法将Mac号分成组?我指的是(00),(16),(3e),(2f),(ba),(b7)
我知道,有一个where
功能,List::Gen
但我无法在我的主机中安装此软件包.那么,我该怎么做呢?
当我尝试访问已经释放的地址时,程序将正常运行.有些货物要避免吗?像一些名为的函数have_alloca(void *p)
可以返回是否p
是有效地址.
我知道valgrind
有tool=memcheck
能做到这一点.但我想知道我是否可以从代码中避免它.
这是一个简单的例子:
#include <stdlib.h>
int main(int argc, char *argv[])
{
int *p = malloc(sizeof(int) * 10);
free(p);
*(p + 1) = 100;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么我可以访问无效地址?程序可以编译运行,没有任何警告.顺便说一句:Linux.
我试着获取usb stick的urb信息.我写的如下:
#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <usb.h>
/* #include <stropts.h> */
/* #include <inttypes.h> */
#include <linux/usbdevice_fs.h>
/* #include <asm/byteorder.h> */
/* #include <linux/usb/ch9.h> */
#define USBDEVFS_REAPURB _IOW('U', 12, void *)
int main(int argc, char *argv[])
{
int fd;
int result;
int i;
struct usbdevfs_urb * receive;
receive = malloc(sizeof (struct usbdevfs_urb));
bzero(receive, sizeof (struct usbdevfs_urb));
char file[30];
strncpy (file, argv[1], 30);
if ((fd = open(file, O_RDWR)) < 0) …
Run Code Online (Sandbox Code Playgroud) 我有一个界面:
type Reader interface {
// Read IV and Master header
ReadMaster(p []byte, full bool) (int, error)
// Read User header
ReadUser(p []byte, full bool) (int, error)
// Read Content data
ReadContent(p []byte) (int, error)
}
Run Code Online (Sandbox Code Playgroud)
我有三个struct
与界面兼容的.所有三个结构都有samve方法ReadUser
.所以我必须这样做:
func (r *s1) ReadUser(buf []byte, full bool) (int, error) {
//.... code 1 ....
}
func (r *s2) ReadUser(buf []byte, full bool) (int, error) {
//.... code 2 ....
}
func (r *s3) ReadUser(buf []byte, full bool) (int, error) …
Run Code Online (Sandbox Code Playgroud) 我只想在我的perl脚本中使用awk命令,如下所示:
$linum = `awk -F "%" '/^\s*kernel/{print NR}' < $grubFile`;
Run Code Online (Sandbox Code Playgroud)
但它会说:Unrecognized escape \s passed through at ./root line 36.
我该如何避免呢?谢谢.
在ruby中,我尝试在运算符' []
' 中将String转换为Int 但是失败了.这是代码(我的输入是14 45
):
STDIN.gets.split(/\s+/).each do |str|
book = tags[str.to_i] # book is just a new variable. tags is an array
end
Run Code Online (Sandbox Code Playgroud)
ruby会因错误而停止:
in '[]': no implicit conversion of String into Integer (TypeError)
所以我将我的代码更改为以下(这个很好用.):
STDIN.gets.split(/\s+/).each do |str|
number = str.to_i # for converting
book = tags[number]
end
Run Code Online (Sandbox Code Playgroud)
这个很好用.但我必须再添加一行进行转换.有没有一种避免这条线的好方法?我的ruby版本是:$: ruby --version ==> ruby 2.0.0p0 (2013-02-24 revision39474) [i686-linux]
嗨大家好,请让我知道为什么你还想关闭这个话题.谢谢.
我重新定义Array#replace
如下.
require 'test/unit'
class Array
def replace (from, to)
each_with_index do |e, i|
self[i] = to if e = from
end
end
end
class TestDriver <Test::Unit::TestCase
def test_replace
book_topic = ['html', 'java', 'css']
book_topic.replace('java', 'ruby')
result_topic = ['html', 'ruby', 'css']
assert_equal book_topic, result_topic
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行该测试用例时,它断言book_topic
是['html', 'ruby', 'ruby']
.我不知道结果book_topic
.谁能告诉我为什么?
我正在用perl写一个小服务器.有一些小问题.当客户给我这样的句子"op:xxx:xxx:xxx"时,我会得到操作.然后根据操作是做什么的.如果op是adduser等,它将起作用.(我使用if op eq"adduser"...)但是当我得到一个"getList:xxx:xxx"并且我得到$ op = getList时,它不能像"if $ op eq"getList那样传递它"".我知道,这一定是我的错.但我找不到它.谢谢大家.
use warnings;
use strict;
package MyPackage;
use base qw(Net::Server);
our %data_base;
our %tag_base;
sub list {
my %resault;
foreach ( keys %tag_base) {
print STDERR $_ . "1";
my @tags = split /:/, $tag_base{$_};
foreach ( @tags) {
$resault{$_} ++;
}
}
my @tags;
foreach ( keys %resault) {
push @tags, "$_,$resault{$_}";
}
$_ = join ";", @tags;
print ;
print STDERR ;
}
sub users {
my $topic = shift; …
Run Code Online (Sandbox Code Playgroud) 我正在写一个小代码,只有五行,但它不能以正确的顺序运行.编译完这段代码后,它会"dir"
先执行,然后再打印我的字符串.
但如果我将其更改为printf ("%s\n", "asdf");
,程序将以正确的顺序运行.我想知道为什么会这样.(PS,我的计算机是用gcc 4.6.2编写的,我也使用了clang但它们也有相同的结果.)谢谢你们每一个人.这是代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf ("%s", "asdf");
system ("dir");
return 0;
}
Run Code Online (Sandbox Code Playgroud)