小编mad*_*per的帖子

如何在linux中使用麦克风获取原始格式的声音

我正在用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)

c linux audio speech-recognition archlinux

6
推荐指数
1
解决办法
6712
查看次数

-mtune = i486和-arch = i486之间有什么不同

我有一个旧的代码需要编译与-m486标志GCC.但没有那面旗帜.然后我发现-mtune=i486并且-arch=i486
我已经阅读了这个页面.但还是不知道哪一个最适合-m486

c linux compiler-construction gcc

5
推荐指数
1
解决办法
794
查看次数

在Perl中是否有一些像zip和fold这样的函数?

我想在perl中使用一些函数,如"zip","fold""map".(就像在Haskell中一样.)我找到了地图并且效果很好.那么,是否有拉链和折叠?非常感谢你.

perl zip map fold

4
推荐指数
3
解决办法
2557
查看次数

如何分割字符串,我的意思是将1234567890转换为12:34:56:78:90

我需要将一些Mac数字(00163e2fbab7)转换为Mac字符串.(带":")

是否有一些很好的方法将Mac号分成组?我指的是(00),(16),(3e),(2f),(ba),(b7)

我知道,有一个where功能,List::Gen但我无法在我的主机中安装此软件包.那么,我该怎么做呢?

非常感谢你!

regex string macos perl

3
推荐指数
3
解决办法
328
查看次数

如何避免访问已释放的地址?

当我尝试访问已经释放的地址时,程序将正常运行.有些货物要避免吗?像一些名为的函数have_alloca(void *p)可以返回是否p是有效地址.
我知道valgrindtool=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.

c linux memory

3
推荐指数
2
解决办法
142
查看次数

如何在linux中获取usb的urb信息

我试着获取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)

c linux usb libusb

2
推荐指数
1
解决办法
4883
查看次数

对于给定的接口,我有三个实现.三个实现如何共享同一个方法?

我有一个界面:

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)

go

2
推荐指数
1
解决办法
75
查看次数

当我在perl中调用shell时,如何转义我的字符串?

我只想在我的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.
我该如何避免呢?谢谢.

linux shell perl awk

1
推荐指数
1
解决办法
154
查看次数

无法在`[]`中将字符串更改为int

在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]

嗨大家好,请让我知道为什么你还想关闭这个话题.谢谢.

ruby typeerror

1
推荐指数
1
解决办法
3636
查看次数

Array.each_with_index未按预期运行

我重新定义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.谁能告诉我为什么?

ruby

0
推荐指数
1
解决办法
126
查看次数

perl"eq"效果不佳.我找不到自己的错

我正在用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)

perl

-3
推荐指数
1
解决办法
333
查看次数

我的c代码不能按顺序运行

我正在写一个小代码,只有五行,但它不能以正确的顺序运行.编译完这段代码后,它会"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)

c

-4
推荐指数
1
解决办法
122
查看次数

标签 统计

c ×5

linux ×5

perl ×4

ruby ×2

archlinux ×1

audio ×1

awk ×1

compiler-construction ×1

fold ×1

gcc ×1

go ×1

libusb ×1

macos ×1

map ×1

memory ×1

regex ×1

shell ×1

speech-recognition ×1

string ×1

typeerror ×1

usb ×1

zip ×1