flask send_file使用

本地服务启动后,客户端访问本地服务器上的静态资源



配置蓝图或路由
from api.local_resource import local_resource
app.register_blueprint(local_resource)
 
 

api设计:

local_resource = Blueprint("local_resource", __name__)


class LocalResource(views.MethodView):
"""

"""
def get(self):
res = local_resource_opera.get_local_resource(request)
return res

def post(self):
pass


local_resource.add_url_rule("/local_resource", view_func=LocalResource.as_view(name="get_local_resource"))


编写service,文件获取规则
import settings
import os
from flask import send_fi
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用STM32F103将音频文件存储到NAND Flash中并通过I2S驱动WM8960播放的示例代码。请注意,此代码仅供参考,您需要根据您的具体情况进行修改和适应。 首先,您需要了解以下几个基本知识: 1. NAND Flash的工作原理和接口 2. STM32F103的GPIO、SPI和I2S模块的使用 3. WM8960的工作原理和寄存器配置 在代码中,我们使用了FatFs文件系统来读取NAND Flash中的音频文件。需要先在代码中配置好FatFs的参数。然后,将音频文件转换为PCM格式,并将其存储在NAND Flash中。 接下来,我们配置STM32F103的GPIO、SPI和I2S模块。需要注意的是,不同的STM32开发板可能会有所不同,您需要根据您的具体情况进行修改。 最后,我们配置WM8960的寄存器,并使用I2S驱动它来播放音频。需要注意的是,WM8960的寄存器配置可能会因不同的应用而有所不同,您需要根据您的需求进行修改。 ``` #include "stm32f10x.h" #include "stm32f10x_spi.h" #include "stm32f10x_gpio.h" #include "stm32f10x_i2s.h" #include "ff.h" #define SPI_NAND_CS_LOW() GPIO_ResetBits(GPIOA, GPIO_Pin_4) #define SPI_NAND_CS_HIGH() GPIO_SetBits(GPIOA, GPIO_Pin_4) #define I2S_WS_PIN GPIO_Pin_12 #define I2S_WS_PORT GPIOB #define I2S_SCK_PIN GPIO_Pin_13 #define I2S_SCK_PORT GPIOB #define I2S_SD_PIN GPIO_Pin_15 #define I2S_SD_PORT GPIOB void SPI_NAND_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; SPI_InitTypeDef SPI_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); SPI_Cmd(SPI1, ENABLE); } void I2S_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; I2S_InitTypeDef I2S_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); GPIO_InitStructure.GPIO_Pin = I2S_WS_PIN | I2S_SCK_PIN | I2S_SD_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(I2S_WS_PORT, &GPIO_InitStructure); RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S); RCC_PLLI2SCmd(ENABLE); while (RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY) == RESET); I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k; I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips; I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b; I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx; I2S_Init(SPI2, &I2S_InitStructure); I2S_Cmd(SPI2, ENABLE); } void WM8960_Init(void) { // TODO: 配置WM8960的寄存器 } void PlayAudio(void) { FIL file; FRESULT res; UINT br; uint8_t buf[512]; uint16_t pcm; res = f_open(&file, "audio.wav", FA_READ); if (res != FR_OK) { return; } SPI_NAND_CS_LOW(); SPI_I2S_SendData(SPI1, 0x00); while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); SPI_I2S_ReceiveData(SPI1); SPI_I2S_SendData(SPI1, 0x0B); while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET); SPI_I2S_ReceiveData(SPI1); SPI_NAND_CS_HIGH(); while (1) { res = f_read(&file, buf, sizeof(buf), &br); if (res != FR_OK || br == 0) { break; } for (int i = 0; i < br; i += 2) { pcm = ((uint16_t)buf[i+1] << 8) | buf[i]; while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, pcm); } } f_close(&file); } int main(void) { SPI_NAND_Init(); I2S_Init(); WM8960_Init(); PlayAudio(); while (1) { } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值