gpt4 book ai didi

ios - 使用从 Web 服务响应中获取的字节播放音频

转载 作者:行者123 更新时间:2023-11-29 04:24:02 25 4
gpt4 key购买 nike

我收到下面的文字

b2NSK5YTVnOxYBZzmNEo5j2VZwsq4DhfHoX9SnQqVVuiynVWl94Tt1a1NFKICtRFbwAd0KJGrnKGbu3NMsjPq6on7W561W3zveYmaa/x//6JFVZx/871/8Ns+/BKmacsSUNI225 G0gCQVnYRyRadZa61N6ZM+kd+ly2RnLE4KPJiULcXAkca+YzYYzfNMKVYqkMP1CEg7lhdcWEoMSCMEXgtwuCcplRNctAfFQNwWBoXjd0xbqk8dVm4tjdhGmTJpHakupbqIC2/5wazxs 6CNn9f/7okiwgAOvPlVrL2roeYfKrWXvXQ8Y81msvaux7Z5qdZe9dBmg0QXKJYqCUp9dtv99gCoCOhlLgKFD6ki1f1l70jh7Z2RpQ6aPlDKEKE0G+uB74ZkEf8fIEs+GUWxOnQejS3 tmj0jF4hwkc+N4+Eb4DXtyDYxYKETSJGj3yl8eG05ulr6ObV1y069r5xneFj1///x9yHzFjbpXGt//4hxAsKTKiWIwJKTjbjbiaQBYDMzIaKJTwYYzhByA3XlC+b7afaGqJVs2EX cgJci6t5287x+KxD2UrIq6gMJwHdSWFHjaJM+dHEmPpwdLgzFMggJdBQlwEQXD5anHi6yKbVlBcTVNQ+lJFzzJIUza3NG/qRQGcdEWU1f8oqWcQqfoOGtRBUv1uu/32AKopkfSsFHmkMuRTShaXEHBnm1Lq06ibo7CG5F1LkXVWp2MWcisq9LBM3U0hBdsSxo7Fo33cMv0c9V5A+xFR3EOPWD+FBAnnv0J3lMuWqozOTNh4SLlXcXVqe9I8TX///xWi+ga6 xr5x//8OOMtmPjf8m1ZEkpONtttppQJkl5hssHVHICulId6WBQ29lG2wU/Og3WU9YuiRViCbXBElY42eHLdPk5VqAjNFJ3NryVVjtcYGBCsVUo8CZMCmHGNZOO6sixLDKrHjollze/ht2X Mnvj+JPFIwj/6//VvJY7NPlWH/+6BIsgADz0HV6y9q7HvoSp1l710OqPNZrL1rscOeqmWGNXa4OtyzENabAa6urpcR1LhAM4JEaisRTHkpeZw4cvpdu+N4rn2A4XVAyY4GoUE03YBXR7A66RFy Klo0/Elj1cqKiix0fGJYNxNAJmEYwMTRailjSKYznDpgRmcSSgTzZG/5SQWp6upaR0Wn7fmdK9LMzgpes6/ClyzJVr/7+6xfJxSg+8gMP1EOGXJBqxZx6L8FCkSnVERcjxmKdEDYVmT6N xlUWal62iVNkrDnWYTfHlnG1FRdNhxjsHRaAnNALI8sFGQUVGuMVTDSarJxLvHmYSaR9WtlIkoj/rWYFQkFORUj6JkfSWUdMuzmrefehYsPoAW+uvpcWSbBI+2HOB5aByEh624zj1ZvTyPUwTm Q3J9VMt4fCoXnEMB9HVALEajmCf2E0h7RCfx2vYWKzIdpSDliSC8dNApaAI0aLAIYcJqgSuJKpEWJqsfhluwyyYorLdXZSJov/WtAqF5D1I+syP1q3d2UUkefegeJAO4qoAEuNt3/0D0DQFKjQEKsdVhd1OCOO9Dk5P1wWEmiX5N7iujDL8rW4rR3EPRFnpeNNpvwiJLvLhhpR+fe9l6fOCQSlox1+43bUClVeZL+5RfS JNpy0YzlFG6q4iZjX9d2zfFGiBb6///3ZMGr/bf+v8ZvHZv9T9Mj/

在网络服务响应中,我想使用上面的字节字符串播放音频。我试过了

NSString *str=[TBXML textForElement:result];
str= [str stringByReplacingOccurrencesOfString:@" " withString:@""];

NSData *data= [[NSData alloc] init];

data = [str dataUsingEncoding:NSUTF8StringEncoding];

if (data)
[objApp.viewAya playAudio:data];

但是,播放器显示错误:操作无法完成。请帮助我使用网络服务从字节数据播放和下载音频。

最佳答案

这是代码

static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";


- (id)dataWithBase64EncodedString:(NSString *)string
{
if (string == nil)
[NSException raise:NSInvalidArgumentException format:nil];
if ([string length] == 0)
return [NSData data];

static char *decodingTable = NULL;
if (decodingTable == NULL)
{
decodingTable = malloc(256);
if (decodingTable == NULL)
return nil;
memset(decodingTable, CHAR_MAX, 256);
NSUInteger i;
for (i = 0; i < 64; i++)
decodingTable[(short)encodingTable[i]] = i;
}

const char *characters = [string cStringUsingEncoding:NSASCIIStringEncoding];
if (characters == NULL) // Not an ASCII string!
return nil;
char *bytes = malloc((([string length] + 3) / 4) * 3);
if (bytes == NULL)
return nil;
NSUInteger length = 0;

NSUInteger i = 0;
while (YES)
{
char buffer[4];
short bufferLength;
for (bufferLength = 0; bufferLength < 4; i++)
{
if (characters[i] == '\0')
break;
if (isspace(characters[i]) || characters[i] == '=')
continue;
buffer[bufferLength] = decodingTable[(short)characters[i]];
if (buffer[bufferLength++] == CHAR_MAX) // Illegal character!
{
free(bytes);
return nil;
}
}

if (bufferLength == 0)
break;
if (bufferLength == 1) // At least two characters are needed to produce one byte!
{
free(bytes);
return nil;
}

// Decode the characters in the buffer to bytes.
bytes[length++] = (buffer[0] << 2) | (buffer[1] >> 4);
if (bufferLength > 2)
bytes[length++] = (buffer[1] << 4) | (buffer[2] >> 2);
if (bufferLength > 3)
bytes[length++] = (buffer[2] << 6) | buffer[3];
}

realloc(bytes, length);
return [NSData dataWithBytesNoCopy:bytes length:length];
}

并以这种方式调用它:-

NSData *try = (NSData*)[self dataWithBase64EncodedString:[dict objectForKey:@"Data"]];
imageview.image = [UIImage imageWithData:try];

希望有帮助......

关于ios - 使用从 Web 服务响应中获取的字节播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12616377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com