小编Dan*_*elY的帖子

使我的python的蓝牙服务器对iOS可见

我一直在努力连接一个蓝牙服务器(使用Bluez或类似的)在一个运行在Linux服务上的Python脚本,一个运行Cordova混合应用程序的iPhone设备.

我正在为后者使用cordova-plugin-ble-central,对于前者我给你的代码如下:

try:
    server_sock = BluetoothSocket(RFCOMM)

    server_sock.bind(("", 0))
    server_sock.listen(1)
    port = server_sock.getsockname()[1]

    uuid = "d507688e-5fa7-11e7-907b-a6006ad3dba0"
    advertise_service(server_sock, "TestService", service_id=uuid, service_classes=[uuid])

    print("Waiting for connection on RFCOMM channel %d" % port)

    client_sock, address = server_sock.accept()
    print "Accepted connection from ", address

    data = client_sock.recv(1024)
    print "received [%s]" % data

    client_sock.close()
    server_sock.close()
except Exception as e:
    print 'ERROR: ' + str(e)
Run Code Online (Sandbox Code Playgroud)

问题是来自iPhone的"scan()"功能结果给了我附近的几个设备,但不是我的...在Android中它的功能非常好!

我错过了什么?有没有办法让它发现?

提前致谢

python bluetooth ios cordova ionic-framework

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

如何在 C++ 项目中使用 TF Lite 库

在过去的 1-2 天里,我一直在为如何构建 TensorFlow Lite 而苦苦挣扎,以便我可以在我自己的 C\C++ 项目中将其用作标头或库。

例如,我有一个带有 main.cpp 的 C++ 项目,代码如下:

#include "tensorflow/lite/model.h"
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"

int main()
{
    std::unique_ptr<tflite::FlatBufferModel> model;
    model = tflite::FlatBufferModel::BuildFromBuffer(h5_converted_tflite, h5_converted_tflite_len);

    tflite::ops::builtin::BuiltinOpResolver resolver;
    std::unique_ptr<tflite::Interpreter> interpreter;
    tflite::InterpreterBuilder(*model, resolver)(&interpreter);

    // Resize input tensors, if desired.
    interpreter->AllocateTensors();

    float* input = interpreter->typed_input_tensor<float>(0);
    // Fill `input`.

    interpreter->Invoke();

    float* output = interpreter->typed_output_tensor<float>(0);
}
Run Code Online (Sandbox Code Playgroud)

我应该从哪里下载\构建什么,以便我可以成功编译此代码?目前它显然说找不到 h 文件,当我克隆 TF 存储库并将其添加到包含文件夹时,它没有找到“flatbuffers.h”文件,当我手动添加它时,它给出我有很多链接错误。任何帮助将不胜感激在这里...

提前致谢

c++ tensorflow tensorflow-lite

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

在windows azure中使用Redis实现进程外缓存

我一直在开发一个网页,显示我在我的天蓝云中的数据库中的表格.为了直接减少对DB的调用以提高性能,我想为页面构建一个缓存.目前,我持有一个内存缓存(进程内)来读取表.现在,我想使进程外-的缓存,应该从何时进行更新写入制成,这意味着插入或更新(因为值被更新或添加后,在内存中缓存将不再有效).

我建议对Redis的,特别图书套,我的问题是在哪里可以找到一些代码示例,以帮助我弄清楚如何启动建设过程外的缓存与它在我当前的项目结合起来.

提前致谢

c# azure redis booksleeve azure-sql-database

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

Java - 将 16 位有符号 pcm 音频数据数组转换为双数组

我正在做一个涉及音频处理的项目。

我正在从文件中提取一段音频,然后想对其进行一些处理。问题是我将音频数据作为字节数组获取,而我的处理是在双数组上(以及后来在复杂数组上......)。

我的问题是如何将收到的字节数组正确转换为双数组继续?

这是我的输入代码:

AudioFormat format = new AudioFormat(8000, 16, 1, true, true);
AudioInputStream in = AudioSystem.getAudioInputStream(WAVfile);
AudioInputStream din = null;
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 
                        8000,
                        16,
                        1,
                        2,
                        8000,
                        true);
din = AudioSystem.getAudioInputStream(decodedFormat, in);
TargetDataLine fileLine = AudioSystem.getTargetDataLine(decodedFormat);
fileLine .open(format);
fileLine .start();

int numBytesRead;
byte[] targetData = new byte[256]; // (samplingRate / 1000) * 32ms

while (true) {
    numBytesRead = din.read(targetData, 0, targetData.length);

    if (numBytesRead == -1) {
        break;
    }

    double[] convertedData;
    // Conversion code goes here...

    processAudio(convertedData); …
Run Code Online (Sandbox Code Playgroud)

java audio bytebuffer bytearray

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

正确实现乒乓游戏

我被要求执行一个名为"ping"和"pong"的pingpong游戏(意思是ping之前没有乒乓)10次.意思是,控制台中的最终输出应该是:"ping!(1)","pong!(1)","ping!(2)","pong!(2)"等.

需求是使用信号量,reetrantlock和倒计时锁存器实现gamepingpongthread.

我的问题是打印顺序并不总是如我所要求的那样,我想知道我做错了什么.

这是代码:

// Import the necessary Java synchronization and scheduling classes.
import java.util.concurrent.Semaphore;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.Condition;

/**
 * @class PingPongRight
 *
 * @brief This class implements a Java program that creates two
 *        instances of the PlayPingPongThread and start these thread
 *        instances to correctly alternate printing "Ping" and "Pong",
 *        respectively, on the console display.
 */
public class PingPongRight
{
    /**
     * @class SimpleSemaphore
     *
     * @brief This class provides a simple counting semaphore …
Run Code Online (Sandbox Code Playgroud)

java concurrency semaphore countdownlatch reentrantlock

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

蓝牙 - 即使在 Python 的 Linux 设备中也能监听配对

我对蓝牙还很陌生,所以这可能是微不足道的,但我仍然会问:

我想通过蓝牙连接 2 个设备 - 一个带有 Linux 设备的移动设备(例如 Raspberry Pi,但另一个......)。

第 1 面 - 移动设备:它有一个应用程序,应与 Linux 设备配对,并向其发送一些数据(此时带有“Hello”的消息)。

第 2 面 - Linux 设备:它应该有一种侦听器来监听设备通过蓝牙连接到它的事实,然后期待数据、接收数据并处理它。

第 1 面对我来说一切都很好且清晰。

至于第二面,目前我只使用一些命令行命令来打开蓝牙,为设备设置一些名称,然后等待扫描。我使用“hciconfig”来完成此操作,在 Python 脚本中依次运行以下命令:

hciconfig hci0 up
hciconfig hci0 name MyDevice
hciconfig hci0 sspmode 1
hciconfig hci0 piscan
Run Code Online (Sandbox Code Playgroud)

此时,我的设备可以被我的手机发现,并且可以成功配对。现在,我被听力部分困住了。我希望 Linux 设备在设备配对时运行某个功能(更喜欢在 Python 中),并期望从中接收数据。我使用 RFCOMM 和 Bluez 在网上阅读了一些链接,但没有成功......

有人可以帮忙吗?谢谢

python linux bluetooth rfcomm

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

Numpy - 带有 2d 数组的多个 3d 数组

我正在尝试以下操作:

给定一个矩阵 A (x, y ,3) 和另一个矩阵 B (3, 3),我想返回一个 (x, y, 3) 矩阵,其中 A 的第三维乘以 B 的值 (与 RGB 图像转换为灰色时类似,只是那些“RGB”值乘以矩阵而不是标量)...

这是我尝试过的:

np.multiply(B, A)
np.einsum('ijk,jl->ilk', B, A)
np.einsum('ijk,jl->ilk', A, B)
Run Code Online (Sandbox Code Playgroud)

所有这些都因尺寸未对齐而失败。

我缺少什么?

python numpy matrix

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

在彩色边缘图中找到最短的有效路径

给定有向图G,边缘颜色为绿色或紫色,G中有顶点S,我必须找到一个算法,找到从GG中每个顶点的最短路径,这样路径最多包含两个紫色边缘(和绿色)尽可能多的).

在删除所有紫色边缘之后我想到了G上的BFS,并且对于最短路径仍然无穷大的每个顶点,做一些尝试找到它的东西,但是我有点卡住,并且它需要很多运行时间...

还有其他建议吗?

提前致谢

algorithm graph-theory graph-algorithm

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

Python - 获取n 1d数组中所有可能的元素总和

给定一个整数n和一个数组a,我想返回一个数组,其中包含a的总和的所有可能值n次.

Example: n = 3, a = [1, 2, 3, 4, 5, 6]

Output: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
Run Code Online (Sandbox Code Playgroud)

第一个元素是1 + 1 + 1,第二个是1 + 1 + 2等.

有没有优雅的方法呢?我已经尝试过循环,但由于事先不知道n,我不知道需要做多少循环.

提前致谢

python

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

编译我的项目时找不到 sqlite3

我正在用 c 语言开发一个小项目,该项目使用 sqlite3 与数据库一起使用。我正在使用 Eclipse CDT。这是相关的代码片段:

#include <sqlite3.h>
int main(int argc, char * argv[]) {
    if (argc < 2) {
        fprintf(stderr,"Error: database name not specified!\n");
        return 1;
    }

    struct sqlite3* db;
    sqlite3_open("movies.db", db);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的项目目录中还有我的文件“sqlite3.so”。当我尝试编译它时,出现“找不到-lsqlite3”错误。

我已在链接器中添加了该文件(在项目属性中),但仍然收到此错误。我能做些什么?

谢谢

c eclipse-cdt shared-libraries

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

在 SQL Server 2008 中插入希伯来语值

我一直在尝试将带有希伯来语 texy 的记录更新到数据库表中,它显示为“??????”。这是我的命令:

UPDATE HebrewTbl
   SET HebrewVal = N'??????'
 WHERE Id = 1
GO
Run Code Online (Sandbox Code Playgroud)

我在互联网上找到的所有解决方案都在开始时添加了 N,但在我的情况下,问题仍然存在。

请指教。提前致谢

sql-server hebrew sql-server-2008

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

使用freets在java中进行语音识别

有没有办法在Java中编写语音识别程序?

我知道有很多技术,我发现freetts看起来很舒服,虽然我成功地编写了一个文本到语音的程序,但没有找到任何语音识别参考.

在这件事上有没有人提到我?

提前致谢

java voice-recognition freetts

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