草庐IT

android - 如何使用 USB 网络摄像头修复 Android 中的拔出 USB 电缆错误?

coder 2023-11-26 原文

我创建了一个基于连接网络摄像头的 android 应用程序。该应用程序在连接网络摄像头时发挥作用。但是当我拔下插头时,我的手机应用程序崩溃并显示“不幸的是应用程序已停止工作”。

视频 Activity :

public class VideoActivity extends AppCompatActivity {
ActionBar actionBar;


public static int mCurrentPosition = -1;
private Handler handler;
private Runnable mRunnable;

//--------------------------------
private static final boolean DEBUG = true;
private static final String TAG = "VIDEO ACTIVITY";


private static final int DEFAULT_WIDTH = 640;  //640
private static final int DEFAULT_HEIGHT = 480; //480

private USBMonitor mUSBMonitor;
private ICameraClient mCameraClient;

private CameraViewInterface mCameraView;

private boolean isSubView;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_video_layout);

    if (mUSBMonitor == null) {
        mUSBMonitor = new USBMonitor(getApplicationContext(), mOnDeviceConnectListener);
        final List<DeviceFilter> filters = DeviceFilter.getDeviceFilters(getApplicationContext(), R.xml.device_filter);
        mUSBMonitor.setDeviceFilter(filters);
    }
    if (savedInstanceState != null) {
        mCurrentPosition = savedInstanceState.getInt("STATE");
    }

    actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);

    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflator.inflate(R.layout.custom_actionbar, null);
    actionBar.setCustomView(v);



    mCameraView = (CameraViewInterface) findViewById(R.id.camera_view);
    mCameraView.setAspectRatio(DEFAULT_WIDTH / (float) DEFAULT_HEIGHT);
        mCameraView.setCallback(mCallback);
}

@Override
public void onBackPressed() {
    finish();
    moveTaskToBack(true);
    super.onBackPressed();
}


private final USBMonitor.OnDeviceConnectListener mOnDeviceConnectListener = new USBMonitor.OnDeviceConnectListener() {
    @Override
    public void onAttach(final UsbDevice device) {
        if (DEBUG) Log.v(TAG, "OnDeviceConnectListener#onAttach:");
        if (!updateCameraDialog() && (mCameraView.getSurface() != null)) {
            tryOpenUVCCamera(true);
        }
    }

    @Override
    public void onConnect(final UsbDevice device, final USBMonitor.UsbControlBlock ctrlBlock, final boolean createNew) {
        if (DEBUG) Log.v(TAG, "OnDeviceConnectListener#onConnect:");
    }

    @Override
    public void onDisconnect(final UsbDevice device, final USBMonitor.UsbControlBlock ctrlBlock) {
        if (DEBUG) Log.v(TAG, "OnDeviceConnectListener#onDisconnect:");
    }

    @Override
    public void onDettach(final UsbDevice device) {
        if (DEBUG) Log.v(TAG, "OnDeviceConnectListener#onDettach:");
        if (mCameraClient != null) {
            mCameraClient.disconnect();
            mCameraClient.release();
            mCameraClient = null;
        }
        updateCameraDialog();
    }

    @Override
    public void onCancel() {
        if (DEBUG) Log.v(TAG, "OnDeviceConnectListener#onCancel:");

    }
};

private boolean updateCameraDialog() {
    final Fragment fragment = getFragmentManager().findFragmentByTag("CameraDialog");
    if (fragment instanceof CameraDialog) {
        ((CameraDialog) fragment).updateDevices();
        return true;
    }
    return false;
}

private void tryOpenUVCCamera(final boolean requestPermission) {
    if (DEBUG) Log.v(TAG, "tryOpenUVCCamera:");
    openUVCCamera(0);
}

public void openUVCCamera(final int index) {
    if (DEBUG) Log.v(TAG, "openUVCCamera:index=" + index);
    if (!mUSBMonitor.isRegistered()) return;
    final List<UsbDevice> list = mUSBMonitor.getDeviceList();
    if (list.size() > index) {

        if (mCameraClient == null)
            mCameraClient = new CameraClient(getApplicationContext(), mCameraListener);
        mCameraClient.select(list.get(index));
        mCameraClient.resize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        mCameraClient.connect();
    }
}

private final CameraViewInterface.Callback mCallback = new CameraViewInterface.Callback() {
    @Override
    public void onSurfaceCreated(final Surface surface) {
        tryOpenUVCCamera(true);
    }

    @Override
    public void onSurfaceChanged(final Surface surface, final int width, final int height) {
    }

    @Override
    public void onSurfaceDestroy(final Surface surface) {

    }
};

private final ICameraClientCallback mCameraListener = new ICameraClientCallback() {
    @Override
    public void onConnect() {
        if (DEBUG) Log.v(TAG, "onConnect:");
        mCameraClient.addSurface(mCameraView.getSurface(), false);
        isSubView = true;
    }

    @Override
    public void onDisconnect() {
        if (DEBUG) Log.v(TAG, "onDisconnect:");

    }
};}

UVC相机:

public class UVCService extends Service {
private static final boolean DEBUG = true;
private static final boolean checkConn = true;
private static final String TAG = "UVCService";

private USBMonitor mUSBMonitor;

public UVCService() {
    if (DEBUG) Log.d(TAG, "Constructor:");
}

@Override
public void onCreate() {
    super.onCreate();
    if (DEBUG) Log.d(TAG, "onCreate:");
    if (mUSBMonitor == null) {
        mUSBMonitor = new USBMonitor(getApplicationContext(), mOnDeviceConnectListener);
        mUSBMonitor.register();
    }
}

@Override
public void onDestroy() {
    if (DEBUG) Log.d(TAG, "onDestroy:");
    if (checkReleaseService()) {
        if (mUSBMonitor != null) {
            mUSBMonitor.unregister();
            mUSBMonitor = null;
        }
    }
    super.onDestroy();
}

@Override
public IBinder onBind(final Intent intent) {
    if (DEBUG) Log.d(TAG, "onBind:" + intent);
    if (IUVCService.class.getName().equals(intent.getAction())) {
        Log.i(TAG, "return mBasicBinder");
        return mBasicBinder;
    }
    if (IUVCSlaveService.class.getName().equals(intent.getAction())) {
        Log.i(TAG, "return mSlaveBinder");
        return mSlaveBinder;
    }
    return null;
}

@Override
public void onRebind(final Intent intent) {
    if (DEBUG)
        Log.d(TAG, "onRebind:" + intent);
}

@Override
public boolean onUnbind(final Intent intent) {
    if (DEBUG)
        Log.d(TAG, "onUnbind:" + intent);
    if (checkReleaseService()) {
        mUSBMonitor.unregister();
        mUSBMonitor = null;
    }
    return true;
}

//********************************************************************************
private final OnDeviceConnectListener mOnDeviceConnectListener = new OnDeviceConnectListener() {
    @Override
    public void onAttach(final UsbDevice device) {
        if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onAttach:");
    }

    @Override
    public void onConnect(final UsbDevice device, final UsbControlBlock ctrlBlock, final boolean createNew) {
        if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onConnect:");

        final int key = device.hashCode();
        CameraServer service;
        synchronized (sServiceSync) {
            service = sCameraServers.get(key);
            if (service == null) {
                service = CameraServer.createServer(UVCService.this, ctrlBlock, device.getVendorId(), device.getProductId());
                sCameraServers.append(key, service);
            } else {
                Log.w(TAG, "service already exist before connection");
            }
            sServiceSync.notifyAll();
        }
    }

    @Override
    public void onDisconnect(final UsbDevice device, final UsbControlBlock ctrlBlock) {
        if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onDisconnect:");
        if (!checkConn) {
            processStopService(UVCService.TAG);
        }
        removeService(device);


        /*if(!checkConn){this.stopService(new Intent(this, MyService.class));}
        ;*/
    }

    @Override
    public void onDettach(final UsbDevice device) {
        if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onDettach:");
        if (!checkConn) {
            processStopService(UVCService.TAG);
        }
        removeService(device);
    }

    @Override
    public void onCancel() {
        if (DEBUG) Log.d(TAG, "OnDeviceConnectListener#onCancel:");
        synchronized (sServiceSync) {
            sServiceSync.notifyAll();
        }
    }
};

// ======================================================================================

private void processStopService(final String tag) {
    Intent intent = new Intent(getApplicationContext(), UVCService.class);
    intent.addCategory(tag);
    stopService(intent);
}

// ======================================================================================
private void removeService(final UsbDevice device) {
    final int key = device.hashCode();
    synchronized (sServiceSync) {
        final CameraServer service = sCameraServers.get(key);
        if (service != null)
            service.release();
        sCameraServers.remove(key);
        sServiceSync.notifyAll();
    }
    if (checkReleaseService()) {
        if (mUSBMonitor != null) {
            mUSBMonitor.unregister();
            mUSBMonitor = null;
        }
    }
}

//********************************************************************************
private static final Object sServiceSync = new Object();
private static final SparseArray<CameraServer> sCameraServers = new SparseArray<CameraServer>();

/**
 * get CameraService that has specific ID<br>
 * if zero is provided as ID, just return top of CameraServer instance(non-blocking method) if exists or null.<br>
 * if non-zero ID is provided, return specific CameraService if exist. block if not exists.<br>
 * return null if not exist matched specific ID<br>
 *
 * @param serviceId
 * @return
 */
private static CameraServer getCameraServer(final int serviceId) {
    synchronized (sServiceSync) {
        CameraServer server = null;
        if ((serviceId == 0) && (sCameraServers.size() > 0)) {
            server = sCameraServers.valueAt(0);
        } else {
            server = sCameraServers.get(serviceId);
            if (server == null)
                try {
                    Log.i(TAG, "waitting for service is ready");
                    sServiceSync.wait();
                } catch (final InterruptedException e) {
                }
            server = sCameraServers.get(serviceId);
        }
        return server;
    }
}

/**
 * @return true if there are no camera connection
 */
private static boolean checkReleaseService() {
    CameraServer server = null;
    synchronized (sServiceSync) {
        final int n = sCameraServers.size();
        if (DEBUG) Log.d(TAG, "checkReleaseService:number of service=" + n);
        for (int i = 0; i < n; i++) {
            server = sCameraServers.valueAt(i);
            Log.i(TAG, "checkReleaseService:server=" + server + ",isConnected=" + (server != null ? server.isConnected() : false));
            if (server != null && !server.isConnected()) {
                sCameraServers.removeAt(i);
                server.release();
            }
        }
        return sCameraServers.size() == 0;
    }
}

//********************************************************************************
private final IUVCService.Stub mBasicBinder = new IUVCService.Stub() {
    private IUVCServiceCallback mCallback;

    @Override
    public int select(final UsbDevice device, final IUVCServiceCallback callback) throws RemoteException {
        if (DEBUG)
            Log.d(TAG, "mBasicBinder#select:device=" + (device != null ? device.getDeviceName() : null));
        mCallback = callback;
        final int serviceId = device.hashCode();
        CameraServer server = null;
        synchronized (sServiceSync) {
            server = sCameraServers.get(serviceId);
            if (server == null) {
                Log.i(TAG, "request permission");
                mUSBMonitor.requestPermission(device);
                Log.i(TAG, "wait for getting permission");
                try {
                    sServiceSync.wait();
                } catch (final Exception e) {
                    Log.e(TAG, "connect:", e);
                }
                Log.i(TAG, "check service again");
                server = sCameraServers.get(serviceId);
                if (server == null) {
                    throw new RuntimeException("failed to open USB device(has no permission)");
                }
            }
        }
        if (server != null) {
            Log.i(TAG, "success to get service:serviceId=" + serviceId);
            server.registerCallback(callback);
        }
        return serviceId;
    }

    @Override
    public void release(final int serviceId) throws RemoteException {
        if (DEBUG) Log.d(TAG, "mBasicBinder#release:");
        synchronized (sServiceSync) {
            final CameraServer server = sCameraServers.get(serviceId);
            if (server != null) {
                if (server.unregisterCallback(mCallback)) {
                    if (!server.isConnected()) {
                        sCameraServers.remove(serviceId);
                        if (server != null) {
                            server.release();
                        }
                        final CameraServer srv = sCameraServers.get(serviceId);
                        Log.w(TAG, "srv=" + srv);
                    }
                }
            }
        }
        mCallback = null;
    }

    @Override
    public boolean isSelected(final int serviceId) throws RemoteException {
        return getCameraServer(serviceId) != null;
    }

    @Override
    public void releaseAll() throws RemoteException {
        if (DEBUG) Log.d(TAG, "mBasicBinder#releaseAll:");
        CameraServer server;
        synchronized (sServiceSync) {
            final int n = sCameraServers.size();
            for (int i = 0; i < n; i++) {
                server = sCameraServers.valueAt(i);
                sCameraServers.removeAt(i);
                if (server != null) {
                    server.release();
                }
            }
        }
    }

    @Override
    public void resize(final int serviceId, final int width, final int height) {
        if (DEBUG) Log.d(TAG, "mBasicBinder#resize:");
        final CameraServer server = getCameraServer(serviceId);
        if (server == null) {
            throw new IllegalArgumentException("invalid serviceId");
        }
        server.resize(width, height);
    }

    @Override
    public void connect(final int serviceId) throws RemoteException {
        if (DEBUG) Log.d(TAG, "mBasicBinder#connect:");
        final CameraServer server = getCameraServer(serviceId);
        if (server == null) {
            throw new IllegalArgumentException("invalid serviceId");
        }
        server.connect();
    }

    @Override
    public void disconnect(final int serviceId) throws RemoteException {
        if (DEBUG) Log.d(TAG, "mBasicBinder#disconnect:");
        final CameraServer server = getCameraServer(serviceId);
        if (server == null) {
            throw new IllegalArgumentException("invalid serviceId");
        }
        server.disconnect();
    }

    @Override
    public boolean isConnected(final int serviceId) throws RemoteException {
        final CameraServer server = getCameraServer(serviceId);
        return (server != null) && server.isConnected();
    }

    @Override
    public void addSurface(final int serviceId, final int id_surface, final Surface surface, final boolean isRecordable) throws RemoteException {
        if (DEBUG)
            Log.d(TAG, "mBasicBinder#addSurface:id=" + id_surface + ",surface=" + surface);
        final CameraServer server = getCameraServer(serviceId);
        if (server != null)
            server.addSurface(id_surface, surface, isRecordable, null);
    }

    @Override
    public void removeSurface(final int serviceId, final int id_surface) throws RemoteException {
        if (DEBUG) Log.d(TAG, "mBasicBinder#removeSurface:id=" + id_surface);
        final CameraServer server = getCameraServer(serviceId);
        if (server != null)
            server.removeSurface(id_surface);
    }

    @Override
    public boolean isRecording(final int serviceId) throws RemoteException {
        final CameraServer server = getCameraServer(serviceId);
        return server != null && server.isRecording();
    }

    @Override
    public void startRecording(final int serviceId) throws RemoteException {
        if (DEBUG) Log.d(TAG, "mBasicBinder#startRecording:");
        final CameraServer server = getCameraServer(serviceId);
        if ((server != null) && !server.isRecording()) {
            server.startRecording();
        }
    }

    @Override
    public void stopRecording(final int serviceId) throws RemoteException {
        if (DEBUG) Log.d(TAG, "mBasicBinder#stopRecording:");
        final CameraServer server = getCameraServer(serviceId);
        if ((server != null) && server.isRecording()) {
            server.stopRecording();
        }
    }

    @Override
    public void captureStillImage(final int serviceId, final String path) throws RemoteException {
        if (DEBUG) Log.d(TAG, "mBasicBinder#captureStillImage:" + path);
        final CameraServer server = getCameraServer(serviceId);
        if (server != null) {
            server.captureStill(path);
        }
    }

};

//********************************************************************************
private final IUVCSlaveService.Stub mSlaveBinder = new IUVCSlaveService.Stub() {
    @Override
    public boolean isSelected(final int serviceID) throws RemoteException {
        return getCameraServer(serviceID) != null;
    }

    @Override
    public boolean isConnected(final int serviceID) throws RemoteException {
        final CameraServer server = getCameraServer(serviceID);
        return server != null ? server.isConnected() : false;
    }

    @Override
    public void addSurface(final int serviceID, final int id_surface, final Surface surface, final boolean isRecordable, final IUVCServiceOnFrameAvailable callback) throws RemoteException {
        if (DEBUG)
            Log.d(TAG, "mSlaveBinder#addSurface:id=" + id_surface + ",surface=" + surface);
        final CameraServer server = getCameraServer(serviceID);
        if (server != null) {
            server.addSurface(id_surface, surface, isRecordable, callback);
        } else {
            Log.e(TAG, "failed to get CameraServer:serviceID=" + serviceID);
        }
    }

    @Override
    public void removeSurface(final int serviceID, final int id_surface) throws RemoteException {
        if (DEBUG) Log.d(TAG, "mSlaveBinder#removeSurface:id=" + id_surface);
        final CameraServer server = getCameraServer(serviceID);
        if (server != null) {
            server.removeSurface(id_surface);
        } else {
            Log.e(TAG, "failed to get CameraServer:serviceID=" + serviceID);
        }
    }
};

最佳答案

您可能应该使用一些 try catch 语句来确保您的程序不会因为 Uncaught Error 而崩溃:

@Override
public void onDettach(final UsbDevice device) {
    if (DEBUG) Log.v(TAG, "OnDeviceConnectListener#onDettach:");
    try {
        if (mCameraClient != null) {
            mCameraClient.disconnect();
            mCameraClient.release();
            mCameraClient = null;
        }
        updateCameraDialog();
    } catch (Exception ex) {
        Log.e("Exception occurred", ex);
    }
}

通常捕获所有异常是不好的做法,因此您应该检查抛出的异常并将捕获的异常更改为该特定异常。

关于android - 如何使用 USB 网络摄像头修复 Android 中的拔出 USB 电缆错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35239658/

有关android - 如何使用 USB 网络摄像头修复 Android 中的拔出 USB 电缆错误?的更多相关文章

  1. ruby - 如何使用 Nokogiri 的 xpath 和 at_xpath 方法 - 2

    我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div

  2. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  3. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  4. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  5. ruby-on-rails - 使用 Ruby on Rails 进行自动化测试 - 最佳实践 - 2

    很好奇,就使用ruby​​onrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提

  6. ruby - 在 Ruby 中使用匿名模块 - 2

    假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于

  7. ruby - 其他文件中的 Rake 任务 - 2

    我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时

  8. ruby-on-rails - Ruby net/ldap 模块中的内存泄漏 - 2

    作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代

  9. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  10. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

随机推荐